Debian

nginx php-fpm index.php 不載入

  • December 14, 2013

我有一個非常簡單的 nginx 和 php-fpm 設置,但是當我嘗試使用我的網站訪問我的網站時,my-website.com我得到一個 403 禁止錯誤,如果我訪問my-website.com/index.php一切正常。這是我的日誌中顯示的內容:

a.ipv4.addr.here - user  [14/Dec/2013:11:46:41 +0100] "GET / HTTP/1.1" 403  192 "https://my-website.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36"

這是ls -lhtdocs 目錄的輸出:

drwxr-xr-x 14 www-data www-data 4.0K Dec 12 16:02 htdocs

我正在執行 http 重定向到 https 以強制使用 ssl,這是配置:

server {
       listen 80;
       listen [::]:80;

       root /var/www/my-domain.com/htdocs/;
       index index.php index.html index.htm /index.php;

       server_name my-domain.com;
       rewrite     ^   https://$server_name$request_uri? permanent;

}

這是偵聽埠 443 的伺服器配置:

server {
       listen 443;
       listen [::]:443;
       server_name my-domain.com;

       root /var/www/my-domain.com/htdocs/;
       index   index.php index.html /index.php;

       access_log /var/log/nginx/my-domain.log;
       ssl on;
       ssl_certificate /etc/ssl/certs/my-domain.com.crt;
       ssl_certificate_key /etc/ssl/private/my-domain.com.key;

       ssl_session_timeout 5m;

       ssl_protocols SSLv3 TLSv1;
       ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
       ssl_prefer_server_ciphers on;

       location / {
               try_files $uri $uri/ =404;
               auth_basic              "Restricted:";
               auth_basic_user_file    .htpasswd;
       }


       location ~ \.php$ {

                auth_basic              "Restricted:";
                auth_basic_user_file    .htpasswd;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
       }
       #deny access on dotfiles
       location ~ /\. {
                deny  all;
       }

}

這是ls -lindex.php 的輸出:

-rwxr-x--x 1 www-data www-data 2.4K Dec 12 11:11 index.php

添加index index.php到您的location /塊中,否則 nginx 不會知道您預設嘗試顯示 index.php。

fastcgi_index選項沒有任何幫助,因為僅在 URI 以 .php 結尾時才考慮它…

引用自:https://unix.stackexchange.com/questions/105138