试图用nginx和gunicorn设置烧瓶

发布于 2025-01-26 22:59:19 字数 1302 浏览 4 评论 0原文

我遵循了一个简单的指南,并试图显示我的烧瓶应用程序,但它不会显示。我正在通过Ubuntu服务器上的SSH运行所有内容。

使用我的flask app和wsgi.py。

在/var/www/application/我的nginx配置

server {
        listen 80;
        server_name application;
 
        access_log /var/log/nginx/application.access.log;
        error_log /var/log/nginx/appliation.error.log;
 
        location / {
                include proxy_params;
                proxy_pass http://unix:/var/www/application/application.sock;
        }
}

中, 位于:/etc/systemd/system/application.service中

[Unit]
Description=application.service - A Flask application run with Gunicorn.
After=network.target
 
[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/application/
ExecStart=/usr/bin/gunicorn --workers 3 --bind unix:/var/www/application.sock wsgi:app
 
[Install]
WantedBy=multi-user.target

已检查所有进程正在运行,SystemD状态可以正常运行,但是当我尝试卷发时,

http://application

我什么都没有得到?

我的app.py

from flask import Flask
 
app = Flask(__name__)
@app.route("/")
def home():
    return "<h1>Nginx & Gunicorn</h1>"

wsgi.py

from main import app
 
if __name__ == "__main__":
    app.run(debug=True)

我在这里缺少什么,如何使它起作用?

I have followed a simple guide, and trying to show my flask application, but it wont show. I am running everything through ssh on a ubuntu server.

Have my flask app and wsgi.py in /var/www/application/

My nginx config is:

server {
        listen 80;
        server_name application;
 
        access_log /var/log/nginx/application.access.log;
        error_log /var/log/nginx/appliation.error.log;
 
        location / {
                include proxy_params;
                proxy_pass http://unix:/var/www/application/application.sock;
        }
}

I have symlinked the file to /etc/nginx/sites-enabled/

Then here is my gunicorn application config
located in: /etc/systemd/system/application.service

[Unit]
Description=application.service - A Flask application run with Gunicorn.
After=network.target
 
[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/application/
ExecStart=/usr/bin/gunicorn --workers 3 --bind unix:/var/www/application.sock wsgi:app
 
[Install]
WantedBy=multi-user.target

Have checked all processes are running, and systemd status ok, but when i try to curl

http://application

I get nothing?

My app.py

from flask import Flask
 
app = Flask(__name__)
@app.route("/")
def home():
    return "<h1>Nginx & Gunicorn</h1>"

wsgi.py

from main import app
 
if __name__ == "__main__":
    app.run(debug=True)

What am I missing here, how to get it working?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吐个泡泡 2025-02-02 22:59:19
ExecStart=/usr/bin/gunicorn --workers 3 --bind unix:/var/www/application.sock wsgi:app

问题是路径/var/www/application.sock ,应该是:/var/www/application/application.sock

您仍然可以查看使用命令服务:
sudo systemctl status&lt; service_name&gt;

了解服务文件中指定的命令是否正确,或者如果应用程序启动问题,请尝试直接从命令行启动:

cd /var/www/application/ && /usr/bin/gunicorn --workers 3 --bind unix:/var/www/application/application.sock wsgi:app
ExecStart=/usr/bin/gunicorn --workers 3 --bind unix:/var/www/application.sock wsgi:app

the problem is the path /var/www/application.sock, it should be: /var/www/application/application.sock

You can still view the status of the service with the command:
sudo systemctl status <service_name>

To understand if the command specified in the service file is correct, or if the application has problems starting, try to start it directly from the command line:

cd /var/www/application/ && /usr/bin/gunicorn --workers 3 --bind unix:/var/www/application/application.sock wsgi:app
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文