我不知道为什么Nginx服务器无法正常工作

时间:2019-10-23 21:13:15

标签: django linux nginx gunicorn supervisord

嗨,我正在尝试使用Nginx + Gunicorn + Supervisor生产一些Django应用。

this guide之后,我能够成功重现所有步骤,但是由于某种原因,我无法使其正常工作。我认为问题出在项目的nginx部分,因为我什至无法提供静态文件进行测试。这是我第一次使用所有这些工具。

配置文件如下:

nginx.conf:

worker_processes 1;

user nobody nogroup;
# 'user nobody nobody;' for systems with 'nobody' as a group instead
error_log  /home/seba94/log/nginx/nginx.error.log warn;
#pid /run/nginx.pid;

events {
  worker_connections 1024; # increase if you have lots of clients
  accept_mutex off; # set to 'on' if nginx worker_processes > 1
  # 'use epoll;' to enable for Linux 2.6+
  # 'use kqueue;' to enable for FreeBSD, OSX
}

http {
  include /etc/nginx/mime.types;
  # fallback in case we can't determine a type
  default_type application/octet-stream;
  access_log /home/seba94/log/nginx/nginx.access.log combined;
  sendfile on;

  upstream app_server {
    # fail_timeout=0 means we always retry an upstream even if it failed
    # to return a good HTTP response

    # for UNIX domain socket setups
    server unix:/tmp/gunicorn.sock fail_timeout=10s;

    # for a TCP configuration
    #server 127.0.0.1:8000 fail_timeout=0;
  }


  server {
    # if no Host match, close the connection to prevent host spoofing
    listen 80 default_server;
    return 444;
  }

  server {
    # use 'listen 80 deferred;' for Linux
    # use 'listen 80 accept_filter=httpready;' for FreeBSD
listen 80;
    client_max_body_size 4G;

    # set the correct host(s) for your site
    server_name reg.rocstar.tv;

    keepalive_timeout 5;

    # path for static files
    root /home/seba94/static;

    location /register/ {
      # checks for static file, if not found proxy to app
      try_files $uri @proxy_to_app;
    }


    location /media/  {
      #path for Django media files
      alias /home/seba94/register-page/register_page/media;
    }

    location /static/ {
      #path for Django static files
      alias /home/seba94/register-page/register_page/static;
    }

    location /todd-logo.png {
      alias /home/seba94/static/todd-logo.png;
    }


    location @proxy_to_app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Host $http_host;
      # we don't want nginx trying to do something clever with
      # redirects, we set the Host: header above already.
      proxy_redirect off;
      proxy_pass http://app_server;
    }

    error_page 500 502 503 504 /500.html;
    location = /500.html {
      root /home/seba94/static;
    }
  }

supervisord.conf:

[supervisord]
logfile=/home/seba94/log/supervisord/supervisord.log

[inet_http_server]
port=127.0.0.1:9001

[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface

[program:register-page-django]
command=/home/seba94/.local/share/virtualenvs/register-page-jYLn8mRO/bin/gunicorn register_page.wsgi -c /home/seba94/conf/gunicorn.conf.py
directory=/home/seba94/register-page/register_page
user=seba94
autostart=true
autorestart=true
stdout_logfile=/home/seba94/log/supervisord/register_page.log
stderr_logfile=/home/seba94/log/supervisord/register_page.err.log

[supervisorctl]

gunicorn.conf.py:

import multiprocessing

#Server socket config
bind = "unix:/tmp/gunicorn.sock"
backlog = 2048

#Workers config. Eventlet is an asynchronus worker
workers = multiprocessing.cpu_count() * 2
worker_class = "eventlet"
worker_connections = 1000


#access-logfile = "/home/seba94/log/gunicorn/gunicorn.log"
#error-logfile = "/home/seba94/log/gunicorn/gunicorn.error.log"


name = "register-page-gunicorn"


#Server mechanics
#daemon = True

我可以使用以下命令成功运行所有进程,而cmd中没有错误:

  • sudo service nginx start
  • sudo supervisord -c /home/seba94/conf/supervisord.conf
  • sudo supervisorctrl start register-page-django

Nginx的状态如下:

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-10-23 20:38:58 UTC; 31min ago
     Docs: man:nginx(8)
  Process: 5552 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 5599 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 5594 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 5601 (nginx)
    Tasks: 2 (limit: 1108)
   CGroup: /system.slice/nginx.service
           ├─5601 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─5760 nginx: worker process

oct 23 20:38:58 register-page-server systemd[1]: Starting A high performance web server and a reverse proxy server...
oct 23 20:38:58 register-page-server systemd[1]: Started A high performance web server and a reverse proxy server.

老实说,我什至在日志文件中都找不到任何错误,所以我不知道为什么我什至看不到我的静态todd-logo.png文件。我也看不到Django应用程序正在运行。任何帮助都超过了欢迎

编辑:

似乎此问题中的所有配置文件和命令均正常,该问题似乎是来自先前项目的防火墙配置。这可能是目前使用这些工具的示例

1 个答案:

答案 0 :(得分:0)

请同时分享问题中curl -v http://domain-name的输出。