简体   繁体   English

我不知道为什么 Nginx 服务器不工作

[英]I don't know why Nginx server is not working

Hi there i'm trying to put in production some django app using nginx + gunicorn + supervisor.嗨,我正在尝试使用 nginx + gunicorn + supervisor 来生产一些 django 应用程序。

Followingthis guide i was able to reproduce all steps with success but for some reason i can't make it work.按照本指南,我能够成功重现所有步骤,但由于某种原因,我无法使其工作。 I believe that the problem is with the nginx part of the project since I'm not able to even serve a static file for testing.我相信问题出在项目的 nginx 部分,因为我什至无法提供 static 文件进行测试。 It's my first time using all these tools.这是我第一次使用所有这些工具。

Config files are as follows:配置文件如下:

nginx.conf: 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.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: 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

I'm able to run successfully all processes with no errors from the cmd using the following commands:我能够使用以下命令成功运行 cmd 中的所有进程而没有错误:

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

Nginx status is the following: 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.

Honestly i can't find any errors not even in the log files so i don't know why i can't even see my static todd-logo.png file.老实说,我什至在日志文件中都找不到任何错误,所以我不知道为什么我什至看不到我的 static todd-logo.png 文件。 Neither can i see the Django app running.我也看不到 Django 应用程序正在运行。 Any help is more than welcomed任何帮助都非常受欢迎

Edit:编辑:

Seems that all config files and commands in this issue are fine, the problem appeared to be a firewall configuration from a previous project.似乎这个问题中的所有配置文件和命令都很好,问题似乎是以前项目中的防火墙配置。 This could be an example of usage of these tools currently working这可能是使用这些当前工作的工具的一个例子

Please share the output of curl -v http://domain-name in the question as well.请在问题中分享 curl -v http://domain-name的 output 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM