代码之家  ›  专栏  ›  技术社区  ›  user204856

无法访问Nginx上具有别名的子目录

  •  0
  • user204856  · 技术社区  · 3 年前

    这里有一个令人烦恼的问题。

    我无法使用别名集访问这个PHP子目录,无论我尝试什么,都会出现404错误。 日志显示 2023/06/10 17:12:23 [error] 36846#36846: *14 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: x, server: example.com, request: "GET /dash/index.php HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php8.1-fpm.sock:", host: "example.com" 2023/06/10 17:12:23 [error] 36846#36846: *14 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: x, server: example.com, request: "GET /favicon.ico HTTP/2.0", host: "example.com", referrer: "https://example.com/dash/index.php"

    server {
        listen 443 ssl http2;
        server_name example.com;
        location /dash/ {
          alias /var/user/dash;
          try_files $uri $uri/ /index.php;
    
          location ~ \.php$ {
              fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
              include fastcgi_params;                       
              fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    
    #          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          }
        }
        # SSL Configuration
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
        ssl_session_cache shared:SSL:10m;
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
        ssl_prefer_server_ciphers off;
    }
    

    我基本上已经尝试了我在网上看到的所有内容,将fastcgi_param更改为另一个选项,在别名处添加斜线,并在位置处尝试了“try_files”。有点被困在这里了。

    0 回复  |  直到 3 年前