php - nginx cannot be started, please help!
为情所困
为情所困 2017-06-08 11:02:00
0
4
1498

The server is down, and Nginx can’t get up after struggling for a long time. I don’t know what’s going on. I am a novice user, please help me!

# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

# service nginx start
Starting nginx (via systemctl):  Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
                                                           [FAILED]
                                                           
# systemctl status nginx
● nginx.service
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2017-06-07 09:22:37 CST; 22s ago
  Process: 20047 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

Jun 07 09:22:37 iZ28qwahedc systemd[1]: Starting nginx.service...
Jun 07 09:22:37 iZ28qwahedc nginx[20047]: nginx: [emerg] open() "/etc/nginx...)
Jun 07 09:22:37 iZ28qwahedc nginx[20047]: nginx: configuration file /etc/ng...d
Jun 07 09:22:37 iZ28qwahedc systemd[1]: nginx.service: control process exit...1
Jun 07 09:22:37 iZ28qwahedc systemd[1]: Failed to start nginx.service.
Jun 07 09:22:37 iZ28qwahedc systemd[1]: Unit nginx.service entered failed s....
Jun 07 09:22:37 iZ28qwahedc systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.    

# /usr/local/nginx/sbin/nginx -t -c /etc/nginx/nginx.conf
nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
                                                       
# journalctl -xe
-- The start-up result is done.
Jun 07 09:38:01 iZ28qwahedc systemd[1]: Starting Session 1059 of user root.
-- Subject: Unit session-1059.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-1059.scope has begun starting up.
Jun 07 09:38:01 iZ28qwahedc CROND[20610]: (root) CMD (/root/php.sh)
Jun 07 09:39:01 iZ28qwahedc systemd[1]: Started Session 1060 of user root.
-- Subject: Unit session-1060.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-1060.scope has finished starting up.
-- 
-- The start-up result is done.
Jun 07 09:39:01 iZ28qwahedc systemd[1]: Starting Session 1060 of user root.
-- Subject: Unit session-1060.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-1060.scope has begun starting up.
Jun 07 09:39:01 iZ28qwahedc CROND[20619]: (root) CMD (/root/php.sh)

Configuration in/usr/local/nginx/conf/nginx.conf

user www www;
worker_processes auto;

error_log /data/wwwlogs/error_nginx.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;

events {
    use epoll;
    worker_connections 8896;
    multi_accept on;
    }

http {
    
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 20m;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 600;
    server_tokens on;
    tcp_nodelay on;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 1000;
    fastcgi_read_timeout 1000;
    fastcgi_buffer_size 1024k;
    fastcgi_buffers 8 1024k;
    fastcgi_busy_buffers_size 1024k;
    fastcgi_temp_file_write_size 1024k;

    #Gzip Compression
    gzip on;
    gzip_buffers 16 8k;
    gzip_comp_level 6;
    gzip_http_version 1.1;
    gzip_min_length 256;
    gzip_proxied any;
    gzip_vary on;
    gzip_types
        text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
        text/javascript application/javascript application/x-javascript
        text/x-json application/json application/x-web-app-manifest+json
        text/css text/plain text/x-component
        font/opentype application/x-font-ttf application/vnd.ms-fontobject
        image/x-icon;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
    open_file_cache max=1000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;
    
    upstream php_fpm_sock{
    server unix:/dev/shm/php-fpm.socket;
    server unix:/dev/shm/php-fpm-b.socket;
    server unix:/dev/shm/php-fpm-c.socket;
    }   
    fastcgi_next_upstream error timeout invalid_header http_503  http_500;

######################## default ############################
    server {
    listen 8080;
    
    server_name www.yuming.com yuming.com 115.22.106.133;
   
    #rewrite ^/(.*)$ http://www.yuming.com/ permanent; 
   
    access_log /data/wwwlogs/access_nginx.log combined;
    root /data/wwwroot/www.yuming.com;
    
    index index.html index.htm index.php;
    
    
    location /nginx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
        }
    location ~ [^/]\.php(/|$) {
        try_files $uri =404;
        #fastcgi_pass remote_php_ip:9000;
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        #fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
        #server里面fastcgi_pass配置 /q/1010000003707164
        #include fastcgi_params;
        #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
        expires 30d;
        access_log off;
        }
    location ~ .*\.(js|css)?$ {
        expires 7d;
        access_log off;
        }
    }

########################## vhost #############################
    include vhost/*.conf;
   
}

/usr/local/nginx/conf/vhost/www.yuming.com.conf configuration

server {
listen 80;
server_name www.yuming.com yuming.com 115.22.106.133;
if ($host != 'www.yuming.com') {
        rewrite ^/(.*)$ http://www.yuming.com/ permanent;
    }
access_log /data/wwwlogs/www.yuming.com_nginx.log combined;
index index.html index.htm index.php;
include /usr/local/nginx/conf/rewrite/wordpress.conf;
include /usr/local/nginx/conf/rocket-nginx.conf;
root /data/wwwroot/www.yuming.com;


location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
    expires 30d;
    access_log off;
    }
location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
   }
}

/usr/local/nginx/logs/error.logError

2017/06/06 21:08:00 [emerg] 6174#0: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
2017/06/07 08:30:32 [emerg] 18497#0: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
2017/06/07 08:56:29 [emerg] 19210#0: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
2017/06/07 09:01:33 [emerg] 19358#0: "fastcgi_pass" directive is duplicate in /usr/local/nginx/conf/nginx.conf:90
2017/06/07 09:14:52 [emerg] 19758#0: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
2017/06/07 09:22:37 [emerg] 20047#0: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
2017/06/07 09:23:32 [emerg] 20089#0: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
2017/06/07 09:26:56 [emerg] 20257#0: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)

/usr/local/php/etc/php-fpm.conf configuration

[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = warning

emergency_restart_threshold = 60
emergency_restart_interval = 60s
process_control_timeout = 5s
daemonize = yes

;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;

[www]
;listen string设置接受 FastCGI 请求的地址。可用格式为:'ip:port','port','/path/to/unix/socket'。每个进程池都需要设置。
listen = /dev/shm/php-cgi.sock
;listen.backlog int设置 listen(2) 的半连接队列长度。“-1”表示无限制。默认值:-1。
listen.backlog = -1
;listen.allowed_clients string设置允许连接到 FastCGI 的服务器 IPV4 地址。等同于 PHP FastCGI (5.2.2+) 中的 FCGI_WEB_SERVER_ADDRS 环境变量。仅对 TCP 监听起作用。每个地址是用逗号分隔,如果没有设置或者为空,则允许任何服务器请求连接。默认值:any。
listen.allowed_clients = 127.0.0.1
;listen.owner string如果使用,表示设置 Unix 套接字的权限。在Linux中,读写权限必须设置,以便用于 WEB 服务器连接。在很多 BSD 派生的系统中可以忽略权限允许自由连接。默认值:运行所使用的用户和组,权限为 0666。
;listen.owner = www
;listen.group = www
;listen.mode = 0666
;user = www
;group = www
listen.owner = www
listen.group = www
listen.mode = 0660
user = www
group = www
;pm string
;设置进程管理器如何管理子进程。可用值:static,ondemand,dynamic。必须设置。
;static - 子进程的数量是固定的(pm.max_children)。
;ondemand - 进程在有需求时才产生(当请求时,与 dynamic 相反,pm.start_servers 在服务启动时即启动。
;dynamic - 子进程的数量在下面配置的基础上动态设置:pm.max_children,pm.start_servers,pm.min_spare_servers,pm.max_spare_servers。
pm = dynamic
;pm.max_children int  pm 设置为 static 时表示创建的子进程的数量,pm 设置为 dynamic 时表示最大可创建的子进程的数量。必须设置。
;该选项设置可以同时提供服务的请求数限制。类似 Apache 的 mpm_prefork 中 MaxClients 的设置和 普通PHP FastCGI中的 PHP_FCGI_CHILDREN 环境变量。
pm.max_children = 50
;pm.start_servers int 设置启动时创建的子进程数目。仅在 pm 设置为 dynamic 时使用。默认值:min_spare_servers + (max_spare_servers - min_spare_servers) / 2。
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 30
pm.max_requests = 500
pm.process_idle_timeout = 10s
request_terminate_timeout = 30
request_slowlog_timeout = 0

pm.status_path = /php-fpm_status
slowlog = log/slow.log
rlimit_files = 2048
rlimit_core = 0

catch_workers_output = yes
;env[HOSTNAME] = iZ28qwahedc
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

If you have anything else you need to read, please leave a message and I will post it right away, thank you!

为情所困
为情所困

reply all(4)
伊谢尔伦

The error here is very clear

Process: 20047 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c
/etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

ExecStartPre is a pre-executed command before systemd starts the service. It is usually used to check the configuration or set environment variables.
You have specified /etc/nginx/nginx.conf as the nginx configuration file, but this file does not exist, so execute Something went wrong

Solution:
Modify /lib/systemd/system/nginx.service, change /etc/nginx/nginx.conf to /usr/local/nginx/conf/nginx.conf
and then execute systemctl daemon-reload && systemctl start nginx

伊谢尔伦
nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory) nginx: configuration file /etc/nginx/nginx.conf test failed

The error message is obvious, the configuration file does not exist
The two are not in the same location:
Needs to be at:/etc/nginx/nginx.conf
Yours is at:/usr/local/nginx/conf/nginx.conf

某草草

Try changing it to this
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/vhost/www.yuming.com.conf

扔个三星炸死你
# systemctl restart nginx
Job for nginx.service failed because a timeout was exceeded. See "systemctl status nginx.service" and "journalctl -xe" for details.

Nginx died immediately

# systemctl status nginx.service
● nginx.service
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; bad; vendor preset: disabled)
   Active: failed (Result: timeout) since Wed 2017-06-07 11:10:59 CST; 1min 42s ago
  Process: 23105 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
  Process: 23102 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)

Jun 07 11:09:28 iZ28qwahedc systemd[1]: Starting nginx.service...
Jun 07 11:09:28 iZ28qwahedc nginx[23102]: nginx: the configuration file /usr/local/nginx/conf/nginx.co...s ok
Jun 07 11:09:29 iZ28qwahedc nginx[23102]: nginx: configuration file /usr/local/nginx/conf/nginx.conf t...sful
Jun 07 11:09:29 iZ28qwahedc systemd[1]: PID file /var/run/nginx/nginx.pid not readable (yet?) after start.
Jun 07 11:10:59 iZ28qwahedc systemd[1]: nginx.service start operation timed out. Terminating.
Jun 07 11:10:59 iZ28qwahedc systemd[1]: Failed to start nginx.service.
Jun 07 11:10:59 iZ28qwahedc systemd[1]: Unit nginx.service entered failed state.
Jun 07 11:10:59 iZ28qwahedc systemd[1]: nginx.service failed.
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template