Nginx не проксирует Gunicorn - PullRequest
0 голосов
/ 18 января 2020

Я пытаюсь развернуть свой Flask проект с использованием Gunicorn и Nginx, но я все еще борюсь.

/ etc / systemd / system / gunicorn3.service

[Unit] Description=Gunicorn service After=network.target

[Service]
User=www-data
Group=adm 
WorkingDirectory=/home/project/
Environment="PATH=/home/project/env/bin" 
ExecStart=/home/project/env/bin/gunicorn --workers 3 --bind unix:cima.sock -m 007 run:app

[Install] WantedBy=multi-user.target

Затем я проверяю, есть ли проблемы, все кажется в порядке

>>sudo systemctl status gunicorn3
gunicorn3.service - Gunicorn service
   Loaded: loaded (/etc/systemd/system/gunicorn3.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-01-17 20:25:01 UTC; 18min ago
 Main PID: 18451 (gunicorn)
    Tasks: 4 (limit: 4915)
   CGroup: /system.slice/gunicorn3.service
           ├─18451 /home/acelerathon_cima_grupo_3/chatbot-grupo-3/chatbot-cima/chatbot-cima-back/cimaenv/bin/python3 /home/acelerathon_cima_grupo_3/chatbo
           ├─18453 /home/acelerathon_cima_grupo_3/chatbot-grupo-3/chatbot-cima/chatbot-cima-back/cimaenv/bin/python3 /home/acelerathon_cima_grupo_3/chatbo
           ├─18454 /home/acelerathon_cima_grupo_3/chatbot-grupo-3/chatbot-cima/chatbot-cima-back/cimaenv/bin/python3 /home/acelerathon_cima_grupo_3/chatbo
           └─18456 /home/acelerathon_cima_grupo_3/chatbot-grupo-3/chatbot-cima/chatbot-cima-back/cimaenv/bin/python3 /home/acelerathon_cima_grupo_3/chatbo

Jan 17 20:25:01 acelerathon-cima-grupo-3 systemd[1]: Started Gunicorn service.
Jan 17 20:25:01 acelerathon-cima-grupo-3 gunicorn[18451]: [2020-01-17 20:25:01 +0000] [18451] [INFO] Starting gunicorn 19.9.0
Jan 17 20:25:01 acelerathon-cima-grupo-3 gunicorn[18451]: [2020-01-17 20:25:01 +0000] [18451] [INFO] Listening at: unix:cima.sock (18451)
Jan 17 20:25:01 acelerathon-cima-grupo-3 gunicorn[18451]: [2020-01-17 20:25:01 +0000] [18451] [INFO] Using worker: sync
Jan 17 20:25:01 acelerathon-cima-grupo-3 gunicorn[18451]: [2020-01-17 20:25:01 +0000] [18453] [INFO] Booting worker with pid: 18453
Jan 17 20:25:01 acelerathon-cima-grupo-3 gunicorn[18451]: [2020-01-17 20:25:01 +0000] [18454] [INFO] Booting worker with pid: 18454
Jan 17 20:25:01 acelerathon-cima-grupo-3 gunicorn[18451]: [2020-01-17 20:25:01 +0000] [18456] [INFO] Booting worker with pid: 18456

/ etc / nginx / sites-enabled / project

server {
    listen 80;
    server_name 127.0.0.1;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/acelerathon_cima_grupo_3/chatbot-grupo-3/chatbot-cima/chatbot-cima-back/cima.sock;
    }
}

А потом я проверил на ошибки.

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Итак, обе службы в порядке, теперь, когда я получаю доступ к http://localhost, я вижу домашнюю страницу Nginx, а не домашнюю страницу приложения Flask

Я не уверен, почему не идет проксирование

1 Ответ

0 голосов
/ 18 января 2020

Добавьте директиву localhost к server_name в Nginx. Nginx используйте эту директиву, чтобы соответствовать блоку сервера для каждого запроса, а в вашем случае localhost не соответствует 127.0.0.1, поэтому он является сервером по умолчанию. Может быть, этот пример поможет понять:

server {
        listen 127.0.0.1:80;
        server_name 127.0.0.1;
        return 200 "At 127.0.0.1\n";
}

server {
        listen 127.0.0.1:80;
        server_name localhost;
        return 200 "At localhost\n";
}

> curl -4 127.0.0.1:80
At 127.0.0.1
> curl -4 localhost:80
At localhost
...