【问题标题】:Removing the port number from URL从 URL 中删除端口号
【发布时间】:2014-07-18 07:05:54
【问题描述】:

我对任何与服务器相关的东西都不熟悉,我正在尝试部署一个 django 应用程序。今天我为该应用购买了一个域名,但在配置它时遇到了问题,因此基本 URL 不需要在其末尾提供端口号。当我只想使用www.trackethecharts.com 时,我必须输入www.trackthecharts.com:8001 才能查看网站。我认为问题出在我的 nginx、gunicorn 或主管配置中。

gunicorn_config.py

command = '/opt/myenv/bin/gunicorn'
pythonpath = '/opt/myenv/top-chart-app/'
bind = '162.243.76.202:8001'
workers = 3
root@django-app:~# 

nginx 配置

server {
    server_name 162.243.76.202;

    access_log off;

    location /static/ {
        alias /opt/myenv/static/;
    }  

    location / {
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }
}

主管配置

[program:top_chart_gunicorn]
command=/opt/myenv/bin/gunicorn -c /opt/myenv/gunicorn_config.py  djangoTopChartApp.wsgi
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor_gunicorn.err.log
stdout_logfile=/var/log/supervisor_gunicorn.out.log

感谢观看。

【问题讨论】:

  • 嗯...您的 nginx 配置发送到 127.0.0.1 上的上游,但 gunicorn 配置为侦听 162.243.76.202;这是故意的吗?这不适用于大多数 ose。
  • 我同意@IfLoop,尝试将 gunicorn 更改为 127.0.0.1,nginx 配置对我来说似乎很好,你正在做代理传递,所以它应该可以工作。
  • 成功了。我将 gunicorn 文件更改为使用 127.0.0.1,我可以按照我想要的方式做所有事情。如果您对该解决方案做出回答,我会接受。

标签: python django nginx gunicorn supervisord


【解决方案1】:

您应该绑定到端口 80,即默认的 http 端口。然后确保在 /etc/nginx/sites-enabled/ 中,您正在侦听端口 80。

通过绑定到端口 80,您无需在 url 中明确指定一个。

【讨论】:

    猜你喜欢
    • 2011-07-04
    • 2015-08-17
    • 2017-01-01
    • 2016-02-06
    • 1970-01-01
    • 2014-12-18
    • 2018-08-16
    相关资源
    最近更新 更多