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

September 19, 2019 925 views
Nginx

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

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

Have another answer? Share your knowledge.

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