Report this

What is the reason for this report?

Why are my server blocks not working on nginx CentOS, they redirect to default nginx folder?

Posted on September 19, 2019

I was following this guide here: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-on-centos-7

here are my two pages: damiantoczek.me buildpc.org

Both show the default Nginx page.

conf.d folder is empty.

sites-available/buildpc.org.conf

server {
  listen 80;
  server_name buildpc.org www.buildpc.org;

  location / {
    root /home/damian/buildpc.org/public;
    index index.html index.htm;
    try_files $uri $uri/ =404;
  }
}

sites-available/damiantoczek.me.conf

server {
  listen 80;
  server_name damiantoczek.me www.damiantoczek.me;

  location / {
    root /home/damian/damiantoczek.me/public;
    index index.html index.htm;
    try_files $uri $uri/ =404;
  }
}

I did the system links to the sites-enabled. I restarted nginx and it shows the default nginx page.

nginx.conf

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;

    include /etc/nginx/sites-enabled/*.conf;
    server_names_hash_bucket_size 64;

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


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello, @damiantoczek

Would you mind checking in the vhosts directory:

/etc/nginx/conf.d/vhosts

The individual config files should be there. On my CentOS 7 / Nginx server this is the directory where you edit/adjust the virtual hosts for the domains.

Let me know how it goes. Alex

Hi @damiantoczek did you fix this?

Hi @alexdo, I have the same problem. Although in recent nginx version on CentOS 7 there is no /conf.d fonder on /etc/nginx. So what can be wrong? Any idea?

Thanks for any help

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.