【问题标题】:Nginx Gunicorn Flask SupervisorCtl - entered site is showing wrong siteNginx Gunicorn Flask SupervisorCtl - 输入的站点显示错误的站点
【发布时间】:2017-08-19 08:29:57
【问题描述】:

我有一个运行 Nginx Gunicorn Flask SupervisorCtl 的网络服务器,但是,在我添加了一个 supervisorctl 配置之后:

[program:websitecom]
command = gunicorn app:app -b localhost:8003
directory = /home/www/flask-deploy/websitecom
user = jd
autostart=true
autorestart=true
stderr_logfile=/var/log/standard_error_websitecom
stdout_logfile=/var/log=standard_out_websitecom

和 nginx 配置:

server {
   server_name website.com;
   listen 80;
   location / {
       proxy_pass http://localhost:8000;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
   }
   location /static {
       alias  /home/www/flask-deploy/websitecom/;
   }
}

app.py 的烧瓶配置:

from flask import Flask, render_template, request
app = Flask(__name__)
app.secret_key = 'asecret'

@app.route("/")
def index():
    return render_template('index.html')

if __name__ == '__main__':
    app.run()

问题在于,它显示了托管在服务器上的先前配置的站点,而不是新域。

有人可以帮忙吗?

谢谢。

【问题讨论】:

    标签: python nginx flask gunicorn


    【解决方案1】:

    发生这种情况时,您需要检查一些事项。第 1 题,更新 NGINX 虚拟主机后,你运行了吗?

    >>> sudo service nginx reload 
    >>> sudo service nginx restart
    

    如果这不是问题,那么您需要做的下一件事是删除所有可能告诉您的浏览器为您的 IP 地址指向错误域的缓存,多个虚拟主机共享同一个 IP。

    您还可以检查以确保您的虚拟主机已添加到您的 sites_enabled 文件夹和您的 sites-available 文件夹中。

    最后,如果与未正确配置 NGINX 相比,这不起作用,则如果正确设置了另一个应用程序,则第一个正确配置的站点将显示在您的域中。例如,如果您的网站 1 运行良好...您添加网站 2 并在 url 中查看,但没有显示网站 2,您会得到网站 1,这可能是网站 2 配置不正确,默认为网站 1。

    【讨论】:

    • 我试过你的code commented 区域 - 没用。我试过deleting cachesites-enabled/sites-avail 都有配置。我试过nginx -t,它说它成功了。还有其他想法吗?
    【解决方案2】:

    我注意到您的 Nginx 服务器块正在代理到端口 8000:

    proxy_pass http://localhost:8000;
    

    当您的 Flask 应用程序在端口 8003 上运行时:

    command = gunicorn app:app -b localhost:8003
    

    我会说您还有一个在端口 8000 上运行的 Flask 应用程序,这就是显示的内容?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-14
      • 2015-10-27
      • 2016-04-26
      • 1970-01-01
      • 2022-05-05
      • 1970-01-01
      • 1970-01-01
      • 2012-05-11
      相关资源
      最近更新 更多