K
K
KuatZ72020-02-24 08:30:20
Nginx
KuatZ7, 2020-02-24 08:30:20

Nginx welcome page instead of website page?

Good afternoon! I ran into a problem when installing nginx on centos7, I created a separate config for the site in the /etc/nginx/conf.d directory with the name test.conf

server {
    listen       80;
    server_name  localhost;
    set $root_path /usr/share/nginx/test;

    gzip  on;
    gzip_disable "msie6";
    gzip_min_length 1000;
    gzip_vary on;
    gzip_proxied    expired no-cache no-store private auth;
    gzip_types      text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;

    root $root_path;
    index index.php;
    expires modified +1w;

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $root_path$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param DOCUMENT_ROOT $root_path;
    }
}


But instead of going to the site with this directory, Nginx's Welcome page opens.
nginx.conf config
# 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/doc/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 {
#        }
#    }

}

Changed the rights and ownership of the /usr/share/nginx/test directory to [- drwxr-xr-x nginx nginx ].
Why doesn't the test.conf config work?
When with nginx -t he writes that everything is OK
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful Can
you please tell me where to look for the error? Thanks in advance to everyone for any replies!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vreitech, 2020-02-24
@fzfx

listen [::]:80;forgot.
Well, you need to go to the address http://localhost/, of course.

V
Vadim Priluzkiy, 2020-02-24
@Oxyd

Try commenting out the server section in the main config. Or switch to another port.

P
Pavel Mezhuev, 2020-02-24
@mezhuev

Return to test.conf listen 80;or remove listen [::]:80;, then reload the configuration via nginx -s reload. If you specify in the browser http://localhost, then everything should work. If the address bar is not localhost, then the request will be processed by the server context in nginx.conf:

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

In this case, you must specify the correct value for the directive server_namein test.conf or use the parameter default_serverin the directive listen(after removing this parameter from nginx.conf).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question