Question

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

Posted September 19, 2019 3.4k 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 {
        }
    }

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.

×
3 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

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

  • Hello, @cfgobel

    I’ve just followed the tutorial on a fresh CentOS 7 droplet and everything is working as expected. If you open the nginx.conf file you should have the following line in the http { block

    include /etc/nginx/conf.d/*.conf;
    

    The directory should contain the default.conf file if you’ve followed the tutorial on a fresh droplet.

    Let me know how it goes.

Submit an Answer