nginx server block configuration not working

February 4, 2017 571 views
Nginx CentOS

Hi There,

I'm a teacher at a school are we are trying to setup a Centos 7 Nginx server to host the kids work while they learn.

We followed the tutorial here at https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-on-centos-7

When we complete the setup, we get a "Welcome to nginx!" page instead of the example page we created for testing.

We have gone over the configuration and googled around for about an hour, we'd really like to get this up before the kids are back on Monday.

Can anybody help us please, and what conf files do you need us to post to assist in the troubleshooting.

Thank you =)

1 Answer

@garrettf4df5779a22ac38a787

If you copied their example verbatim, then NGINX is going to pull content from:

/usr/share/nginx/html

This is defined by the root directive in the server block. To point that to your own directory, you will need to change that directive to match your custom directory.

So if you're using:

server {
    listen  80;
    server_name localhost;

    location / {
        root  /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root  /usr/share/nginx/html;
    }
}

You'll need to change root /usr/share/nginx/html; in the location / block. There are, however, better ways to setup server blocks, but for the purpose of setting up an example, that's all that you need to do.

Once you save the changes, you'll need to restart NGINX using:

systemctl reload nginx

or

systemctl restart nginx

If we throw PHP, NodeJS, or another language in to the picture, we need to change things around.

Have another answer? Share your knowledge.