【问题标题】:NGINX attempts to load from /usr/share/nginx/html/*NGINX 尝试从 /usr/share/nginx/html/* 加载
【发布时间】:2021-11-18 18:42:05
【问题描述】:

启用 SSL 后我的 nginx 正在尝试从 /usr/share/nginx/html/* 加载

我已从可用站点和已启用站点中删除默认值 据我所见,任何地方都没有对 /usr/share/nginx/html 的引用,并且我的 ROOT 变量设置正确..

我的站点启用是来自站点可用的符号链接

域 SSL

    server {
        listen 443 ssl;
        listen [::]:443 ssl;
    include snippets/self-signed.conf;
    include snippets/ssl-params.conf;
        root /var/www/mydomain/html;
        index index.html index.htm index.nginx-debian.html;

        server_name my_domain_here www.my_domain_here;

        location / {
                try_files $uri $uri/ =404;
        }
        location ~ .+\.unityweb$ {
    add_header Content-Encoding gzip;
    }
    location ~* ^.*\.(js)$ {
            types {}
            default_type application/javascript;
            }
           
            location ~* ^.*\.(wasm)$ {
            types {}
            default_type application/wasm;
            }
            location ~* ^.*\.(wasm.gz)$ {
            gunzip on;
            gzip off;
            types {}
            default_type application/wasm;
            add_header Content-Encoding gzip;
            }
            location ~* ^.*\.(framework.js.gz|js.gz)$ {
            gunzip on;
            gzip off;
            types {}
            default_type application/javascript;
            add_header Content-Encoding gzip;
            }
           
            location ~* ^.*\.(data.gz|symbols.json.gz)$ {
            gunzip on;
            gzip off;
            types {}
            default_type application/octet-stream;
            add_header Content-Encoding gzip;
            }
gzip on;

gzip_vary on;

gzip_proxied any;

gzip_comp_level 6;

gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
}

域 HTTPS 重定向 /etc/sites-available/domain.com

server {
    listen 80;
    listen [::]:80;
    server_name my_domain_here www.my_domain_here

    return 302 https://$server_name$request_uri;

}

我的 nginx.conf(完全默认没有更改)

    user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

error.log 的输出

2021/11/17 22:47:50 [error] 105470#105470: *1 "/usr/share/nginx/html/unity/index.html" is not found (2: No such file or directory), client: *, server: *, request: "GET /unity/ HTTP/1.1", host: "*"
2021/11/17 22:47:54 [error] 105470#105470: *3 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: *, server: *, request: "GET /favicon.ico HTTP/1.1", host: "*", referr>
2021/11/17 23:16:55 [error] 105470#105470: *6 open() "/usr/share/nginx/html/index.php" failed (2: No such file or directory), client: *, server: *, request: "GET /index.php HTTP/1.1", host: "*"

【问题讨论】:

  • 您已编辑错误日志,因此您需要检查它。哪个server 产生了错误?您是使用浏览器还是 curl、http 或 https 进行测试? curl -I http://my_domain_here/ 会生成 302 响应吗?
  • 嘿,服务器:在错误日志中是我自己的域。我没有得到 302 响应,服务器给了我一个在 http 上找不到的 404。与 HTTPS 相同。
  • 2021/11/18 11:09:03 [warn] 611#611: server name "https://my_domain_here$request_uri" has suspicious symbols in /etc/nginx/sites-enabled/my_domain.com:6 2021/11/18 11:09:03 [warn] 611#611: "ssl_stapling" ignored, issuer certificate not found for certificate "/etc/ssl/certs/nginx-selfsigned.crt" 2021/11/18 11:11:34 [error] 613#613: *1 "/usr/share/nginx/html/index.html" is not found (2: No such file or directory), client: 162.158.183.134, server: my_domain_here, request: "HEAD / HTTP/1.1", host: "my_domain_here" 是现在生成的错误。 Nginx -T 显示除 /var 之外的其他根目录
  • 您似乎在server_name 语句的末尾缺少;,并且return 302 https://$server_name$request_uri 行被解释为更多服务器名称。此外,您不会在配置中找到 /usr/share/nginx/html - 当没有 root 语句存在时,这是默认设置。

标签: nginx nginx-config


【解决方案1】:

我的问题已通过将两个单独文件中的两个可用站点合并为一个来解决。

不确定是什么问题,可能是我试图在两个文件中提供相同的根目录和 server_name。

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2014-12-13
  • 2017-12-05
  • 1970-01-01
  • 2018-12-15
  • 2019-10-15
  • 2017-11-22
  • 1970-01-01
  • 2015-05-25
  • 2017-09-18
相关资源
最近更新 更多