我已經成功安裝了使用PHP-FPM的nginx,但不幸的是,當從不同目錄加載我的php文件時遇到了一些麻煩。我所有的文件都位於/ var/www/html的子目錄中(例如,所有的css文件都位於/ var/www/html/css中,所有的javascript文件都位於/ var/www/html/js中,所有的php - 文件位於/ var/www/html/php)。 根據這個,我改變了根目錄路徑爲我的PHP文件到/ var/www/html等/ PHP:nginx:403在單獨目錄下的php文件被禁止
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php home.php;
server_name _;
location/{
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html/php;
include snippets/fastcgi-php.conf;
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
不幸的是,使用我的Web瀏覽器訪問我的nginx服務器時,我收到錯誤403 (禁止)。當直接訪問我的index.php(http://192.168.2.109/index.php)時,一切正常。所以,我認爲這意味着文件許可權是正確的,但nginx無法索引/ var/www/html/php目錄。此外,/var/log/nginx/error.log包括:
2017/05/28 07:49:56 [error] 13678#13678:* 1目錄索引「/ var/www/html /」是禁,客戶端:192.168.2.101,服務器:_,請求: 「GET/HTTP/1.1」,主持人:
我已經嘗試過讓自動索引並添加指數符在 「192.168.2.109」 「location〜.php $ {」部分沒有成功。其結果是一樣的:(
有沒有人有一個想法,我在做什麼在Nginx 403 error: directory index of [folder] is forbidden錯誤/缺少在這裏所有的建議並沒有解決我的問題
很確定你只需要一個默認索引? https://stackoverflow.com/questions/10002439/make-index-html-default-but-allow-index-php-to-be-visited-if-typed-in – Joe
nginx是否有一個「DefaultIndex」指令配置文件?提供的鏈接顯示了htaccess的指令,但我沒有使用htaccess。 – Nrgyzer
它不會是一個nginx的東西,它將是一個Web服務器配置的事情。我不知道如何處理所有可能的服務器設置。我知道如果你沒有在URL中指定一個索引,那麼.htaccess中的DirectoryIndex聲明就可以工作,但我不知道如何讓Web服務器自動完成。我知道服務器可以被設置爲爲目錄遍歷拋出一個禁止的錯誤,這就是爲什麼很多網站在他們不希望人們玩耍的目錄中只有一個空白的index.html。 – Joe