老师帮我看下

来源:16-2 nginx + uwsgi 实现多进程访问

慕妹4270370

2019-07-12

我的配置

server {
        listen 80 default_server;
        server_name shlianggu.com;
        location / {
                try_files $uri @yourapplication;
        }

        location @yourapplication{
                include uwsgi_params;
                uwsgi_pass unix:/root/data/www/logs/order.sock;
        }

}

(python3_vir) [root@iZbp1i0t9v2ixxhu5e9tewZ conf.d]# sudo service nginx restart
Redirecting to /bin/systemctl restart  nginx.service
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
(python3_vir) [root@iZbp1i0t9v2ixxhu5e9tewZ conf.d]# systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2019-07-12 23:20:40 CST; 7s ago
  Process: 16396 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
  Process: 16395 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ nginx[16396]: nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/nginx.conf:39
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ nginx[16396]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: nginx.service: control process exited, code=exited status=1
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: Unit nginx.service entered failed state.
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: nginx.service failed.
(python3_vir) [root@iZbp1i0t9v2ixxhu5e9tewZ conf.d]# journalctl -xe
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has failed.
-- 
-- The result is failed.
Jul 12 23:15:19 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: Unit nginx.service entered failed state.
Jul 12 23:15:19 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: nginx.service failed.
Jul 12 23:15:19 iZbp1i0t9v2ixxhu5e9tewZ polkitd[443]: Unregistered Authentication Agent for unix-process:16346:19828776 (system bus name :1.832, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale e
Jul 12 23:20:01 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: Started Session 403 of user root.
-- Subject: Unit session-403.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-403.scope has finished starting up.
-- 
-- The start-up result is done.
Jul 12 23:20:01 iZbp1i0t9v2ixxhu5e9tewZ CROND[16373]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 12 23:20:01 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: Starting Session 403 of user root.
-- Subject: Unit session-403.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-403.scope has begun starting up.
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ sudo[16377]:     root : TTY=pts/0 ; PWD=/etc/nginx/conf.d ; USER=root ; COMMAND=/sbin/service nginx restart
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ polkitd[443]: Registered Authentication Agent for unix-process:16378:19860877 (system bus name :1.835 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedes
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: Starting The nginx HTTP and reverse proxy server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has begun starting up.
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ nginx[16396]: nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/nginx.conf:39
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ nginx[16396]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: nginx.service: control process exited, code=exited status=1
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has failed.
-- 
-- The result is failed.
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: Unit nginx.service entered failed state.
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ systemd[1]: nginx.service failed.
Jul 12 23:20:40 iZbp1i0t9v2ixxhu5e9tewZ polkitd[443]: Unregistered Authentication Agent for unix-process:16378:19860877 (system bus name :1.835, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale e
Jul 12 23:20:48 iZbp1i0t9v2ixxhu5e9tewZ sshd[16402]: Bad protocol version identification '' from 171.34.179.216 port 35692
lines 4415-4461/4461 (END)

多谢老师

[root@iZbp1i0t9v2ixxhu5e9tewZ ~]# vim /etc/nginx/nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
"/etc/nginx/nginx.conf" 90L, 2467C 

老师 这里确实有 default_server;
这里也有一个 server
那是不是要把这个server 和自己创建的 注释掉一个还是要把这个文件都删除

============================

============================
我把

修改为

server {
       listen 80;
       server_name shlianggu.com;
       location / {
               try_files $uri @yourapplication;
       }
 
       location @yourapplication{
               include uwsgi_params;
               uwsgi_pass unix:/root/data/www/logs/order.sock;
       }
 
}

vim /etc/nginx/nginx.conf
这个文件我注释了一部分

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        #listen       80 default_server;
        #listen       [::]:80 default_server;
        #server_name  _;
        #root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        #include /etc/nginx/default.d/*.conf;

        #location / {
        #}

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}


启动sudo service nginx restart

报错
图片描述

老师 是不是/etc/nginx/nginx.conf 这里我注释的不对

我又修改了 /etc/nginx/nginx.conf 里的

图片描述

重启访问成功

写回答

2回答

编程浪子

2019-07-13

你好


server {
       listen 80;
       server_name shlianggu.com;
       location / {
               try_files $uri @yourapplication;
       }

       location @yourapplication{
               include uwsgi_params;
               uwsgi_pass unix:/root/data/www/logs/order.sock;
       }

}

0
2
慕妹4270370
非常感谢!多谢
2019-07-14
共2条回复

编程浪子

2019-07-13

你好

nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/nginx.conf:39

已经提示错了,有两个地方设置了 default_server

0
1
慕妹4270370
老师,请再看我问题描述
2019-07-13
共1条回复

Python Flask构建微信小程序订餐系统(可用于毕设)

微信小程序 + Python Flask 打造订餐系统全栈应用,可用于毕设。

1709 学习 · 1889 问题

查看课程