0

I can't figure out why nginx is serving some content from /usr/share/nginx/html when I have my config files specifying /var/www/html. This is on Ubuntu 18.04, please give me a clue, thanks.

user@Rproxy-ubuntu18:/etc/nginx$ grep "root" -R /etc/nginx/
/etc/nginx/nginx.conf: root /var/www/html;
/etc/nginx/nginx.conf:# root /var/www/html;
/etc/nginx/sites-enabled/server00.conf: root /var/www/html;
/etc/nginx/sites-enabled/server00.conf: root /var/www/html;
/etc/nginx/sites-enabled/server03.conf: root /var/www/html;
/etc/nginx/sites-enabled/server08.conf: root /var/www/html;
/etc/nginx/sites-enabled/server07.conf: root /var/www/html;
/etc/nginx/sites-enabled/server05.conf: root /var/www/html;
/etc/nginx/sites-enabled/server13.conf: root /var/www/html;
/etc/nginx/sites-enabled/server11.conf: root /var/www/html;
/etc/nginx/sites-enabled/server06.conf: root /var/www/html;
/etc/nginx/sites-enabled/server12.conf: root /var/www/html;
/etc/nginx/sites-enabled/server04.conf: root /var/www/html;
/etc/nginx/sites-enabled/server09.conf: root /var/www/html;
/etc/nginx/sites-enabled/server10.conf: root /var/www/html;
/etc/nginx/sites-enabled/server02.conf: root /var/www/html;
/etc/nginx/sites-enabled/server01.conf: root /var/www/html;
/etc/nginx/sites-enabled/server14.conf: root /var/www/html;
/etc/nginx/sites-enabled/server00.conf.save: root /var/www/html;
/etc/nginx/sites-enabled/server00.conf.save: root /var/www/html;

Main config file

#user  nobody;
worker_processes  1;

error_log  /var/log/nginx/error.log;
error_log  /var/log/nginx/error.log  notice;
error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    server_names_hash_bucket_size 128;

    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/ssl/dhparam.pem;

    ssl_certificate      '/etc/nginx/ssl/star.crt';
    ssl_certificate_key  '/etc/nginx/ssl/star_example_com.key';

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;


## Define redirects ##
##
    server {
       listen         80;
       return         301 https://$host$request_uri;
    }
    server {
        listen       443 ssl default_server;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/localhost.access.log  main;

        location =/favicon.ico {
            root /var/www/html;
            index  sites.html sites.htm;
        }

        #this section should disable all caching of our static pages
        location ~* \.(js|css|png|jpg|jpeg|gif|ico|html|htm)$ {
          try_files $uri /index.php?$query_string;
          expires 1d;
          add_header Pragma "no-cache";
          add_header Cache-Control "no-cache, no-store, must-revalidate";
        }

        error_page  404              /sites.html;

        # redirect server error pages to the static page /sites.html
        #
        error_page   500 502 503 504  /sites.html;
        location = /sites.html {
            root /var/www/html;
        }
    }
include /etc/nginx/sites-enabled/*.conf;
}
3
  • try nginx -T | grep "/usr/share/nginx/" it could be a alias not root
    – Drifter104
    May 28, 2019 at 16:25
  • OK, don't exactly know how to read that but this is the answer; user@Rproxy-ubuntu18:~$ sudo nginx -T | grep "/usr/share/nginx/" [sudo] password for user: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
    – maxburn
    May 28, 2019 at 16:51
  • Your default server does not specify a root, so the default value (probably /usr/share/nginx/html) will be used instead. May 28, 2019 at 17:03

1 Answer 1

0

try this. I think the issue is because you have the root inside the location, so by default nginx grabs /usr/share/nginx/

server {
        listen       443 ssl default_server;
        server_name  _;
        root /var/www/html;
        index  sites.html sites.htm;
        #charset koi8-r;

        #access_log  logs/localhost.access.log  main;

        #this section should disable all caching of our static pages
        location ~* \.(js|css|png|jpg|jpeg|gif|ico|html|htm)$ {
          try_files $uri /index.php?$query_string;
          expires 1d;
          add_header Pragma "no-cache";
          add_header Cache-Control "no-cache, no-store, must-revalidate";
        }

        error_page  404              /sites.html;
    }
1
  • Thanks, in test that behaves as I was expecting.
    – maxburn
    May 28, 2019 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.