如何使用UWSGI使用NGINX将本地IP地址分配给公共IP/端口地址?

发布于 2025-02-11 11:34:44 字数 1036 浏览 0 评论 0原文

我有一个使用本地IP地址和端口80在本地服务器中运行的Web应用程序。但是,我希望能够从Internet访问Web应用程序。因此,我从电信公司获得了公共IP地址。我已经配置了nginx服务器,如下所示:

upstream django {
        server unix:///my_path/my_project.sock; 
        # server 127.0.0.1:8000;
    }
    
    # configuration of the server
    server {
        # the port your site will be served on
        listen      80;
        # the domain name it will serve for
        server_name local_ip_address;
        charset     utf-8;
    
        # max upload size
        client_max_body_size 75M;
    
        # Django media
        location /media  {
            alias /my_path/media;  
        }
    
        location /static {
            alias /my_path/static;
        }
        location / {
            uwsgi_pass  django;
            include     /my_path/uwsgi_params; 
        }
    }

在我的sett.py文件中,我在wasse_hosts = ['local IP地址']中使用了本地IP地址。但是在我的防火墙中,我将此IP转发给了公众。 我已经完成了所有NGINX配置。当我从本地IP地址运行应用程序时,它可以很好地工作,但是我从公共IP运行了应用程序,它显示的页面找不到。 如何将本地IP地址分配给公众? 请协助。

I have a web application that is running in a local server using a local IP address and the port 80. However, I would like to be able to access the web application from the Internet. Thus, I have got a public a IP address from a telecommunication company. I have configured the NGINX server as followed:

upstream django {
        server unix:///my_path/my_project.sock; 
        # server 127.0.0.1:8000;
    }
    
    # configuration of the server
    server {
        # the port your site will be served on
        listen      80;
        # the domain name it will serve for
        server_name local_ip_address;
        charset     utf-8;
    
        # max upload size
        client_max_body_size 75M;
    
        # Django media
        location /media  {
            alias /my_path/media;  
        }
    
        location /static {
            alias /my_path/static;
        }
        location / {
            uwsgi_pass  django;
            include     /my_path/uwsgi_params; 
        }
    }

In my setting.pyfile, I have used the local IP address in the ALLOWED_HOSTS = ['local IP address']. But in my firewall, I have forwarded this IP to the public one.
I have done all the nginx configurations. When I run the application from the local IP address, it is working perfectly, but I run the application from the public IP, it is showing page not found.
How can I assign the local IP address to the public one?
Please, assist.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文