Search code examples
phpnginxcentos

change nginx root directory in centos 7


How to change nginx root directory in centos 7 ?

I create default.conf in ‍/etc/nginx/conf.d directory and placed the following code

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root         /var/www/test;

    # 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 {
    }
}

But when start nginx with service nginx start returns this error

Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

Edited

output of 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 Sun 2019-07-07 19:21:49 IRDT; 11min ago

Process: 9976 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)

Process: 10101 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)

Process: 10099 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Main PID: 9978 (code=exited, status=0/SUCCESS)


Solution

  • nginx -t to test your configuration

    if the error is caused by multiple server name, try deleting this default_server from your configuration