nginx 根路径问题;从错误的文件夹提供内容

nginx 根路径问题;从错误的文件夹提供内容

当我的配置文件指定 /var/www/html 时,我不明白为什么 nginx 会从 /usr/share/nginx/html 提供某些内容。这是在 Ubuntu 18.04 上,请给我一个提示,谢谢。

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;

主配置文件

#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;
}

答案1

试试这个。我认为问题是因为您在位置内有根目录,因此默认情况下 nginx 会抓取 /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;
    }

相关内容