Django 使用nginx配置Gunicorn-nginx在端口8000上运行时显示500内部服务器错误

Django 使用nginx配置Gunicorn-nginx在端口8000上运行时显示500内部服务器错误,django,nginx,deployment,gunicorn,production,Django,Nginx,Deployment,Gunicorn,Production,在本地计算机(而不是服务器)上设置nginx和Gunicorn时出现问题。我有一个Django项目,我希望能够通过http://localhost:8000/. 在我的nginx正常运行之前,我的Gunicorn服务器能够成功启动。然而,一旦我配置了我的nginx服务器,现在我的Gunicorn服务器将不会启动,因为nginx已经在我的本地主机上的端口8000上运行。当我访问http://localhost:8000/ 我得到500-内部服务器错误。当我访问http://localhost:80

在本地计算机(而不是服务器)上设置nginx和Gunicorn时出现问题。我有一个Django项目,我希望能够通过http://localhost:8000/. 在我的nginx正常运行之前,我的Gunicorn服务器能够成功启动。然而,一旦我配置了我的nginx服务器,现在我的Gunicorn服务器将不会启动,因为nginx已经在我的本地主机上的端口8000上运行。当我访问http://localhost:8000/ 我得到500-内部服务器错误。当我访问http://localhost:80/不过,我还是欢迎来到nginx!网页

为了配置nginx和Gunicorn,我遵循了以下步骤,跳过了步骤5到步骤7(包括步骤5到步骤7)。我必须注意,在我的/etc/nginx中,可用的站点和启用站点的目录不存在,所以我必须创建它们

我的/etc/nginx/sites目录中只有两个文件可用——default和mydjangoproject。两者都有相同的内容,并且都启用了/etc/nginx/sites中的符号链接。内容包括:

server {
    listen 8000;
    server_name 127.0.0.1;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /production_static/ {
        root /home/john/Documents/Django_projects/mydjangoproject/Version_2/mydjangoproject;
    }

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:8000;
    }
}
以下是我的Django项目的settings.py文件的相关部分:

以下是/var/log/nginx/error.log中的错误日志:


我用谷歌搜索了这些错误,但什么也没找到。有人能告诉我为什么我的nginx显示500-内部服务器错误,如果可能的话,我如何让Gunicorn和nginx在相同的地址和端口上运行?

正如@iklinac所提到的,您不能将两个端口配置为相同的id。端口应该是80。不像你在原来的帖子里说的那样

server {
    listen 80;
    server_name server_domain_or_IP;
}

有两件事不能在networks 101的同一端口上侦听,您正在使nginx侦听8000,但代理到中的同一端口config@iklinac好啊您能告诉我如何更改配置文件以便修复它吗?
2020/12/20 11:58:09 [emerg] 23584#23584: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:01:59 [emerg] 23773#23773: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:02:04 [emerg] 23775#23775: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:02:05 [emerg] 23777#23777: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:12:25 [error] 22879#22879: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "127.0.0.1"
2020/12/20 13:51:08 [error] 22879#22879: *3 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost"
2020/12/20 13:55:01 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:01 [error] 25938#25938: *1 open() "/etc/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: , request: "GET /favicon.ico HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:04 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:21 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:21 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:22 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:23 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:56:00 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:56:48 [warn] 25999#25999: conflicting server name "127.0.0.1" on 0.0.0.0:8000, ignored
2020/12/20 13:57:11 [warn] 26011#26011: conflicting server name "127.0.0.1" on 0.0.0.0:8000, ignored
2020/12/20 13:57:14 [alert] 26013#26013: *1013 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 13:57:15 [alert] 26013#26013: *2025 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 13:57:16 [alert] 26013#26013: *3037 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 13:57:31 [alert] 26013#26013: *4050 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 14:01:02 [alert] 26013#26013: *5064 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 14:01:04 [alert] 26013#26013: *6076 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
server {
    listen 80;
    server_name server_domain_or_IP;
}