[英]403 error on PHP files with nginx, PHP-FPM and docker
我將 docker-compose 與以下docker-compose.yml
一起使用:
web_db:
image: mariadb:latest
restart: always
volumes:
- ./var/mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: "1234"
web_front:
image: nginx
restart: always
ports:
- 80:80
links:
- web_fpm
volumes:
- ./www:/var/www/html:rw
- ./etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
web_fpm:
build: ./PHP-FPM/
restart: always
links:
- web_db:mysql
volumes:
- ./www:/var/www/html
nginx conf 是:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
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/x-javascript text/xml application/xml application/xml+rss text/javascript;
server {
listen 80;
server_name localhost;
root /var/www/html;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
root /var/www/html;
fastcgi_pass web_fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
}
}
如果我創建index.html
。 但是如果我想訪問index.php
,我有一個 403 錯誤和以下日志 docker-compose:
web_front_1 | 2016/05/12 12:59:44 [error] 7#7: *1 directory index of "/var/www/html/" is forbidden, client: IP, server: localhost, request: "GET / HTTP/1.1", host: "IP"
web_front_1 | IP - - [12/May/2016:12:59:44 +0000] "GET / HTTP/1.1" 403 197 "-" "Mozilla/5.0 (Linux; Android 6.0.1; A0001 Build/MMB29X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.105 Mobile Safari/537.36"
我已經嘗試過在其他問答中找到的建議(比如這里),但我無法讓它發揮作用。
從您的日志中,我看到您正在嘗試訪問/
位置。 而且我在您的 nginx 配置中沒有看到會攔截此類請求的條目。 所以我假設在這種情況下:
/
nginx 的請求,嘗試從指定的root
提供靜態文件;index.html
並且您不會覆蓋此設置。 這就是為什么當您添加index.html
時它開始正常工作的原因; 如果您使用/index.php
發出請求,它很可能應該開始工作
您應該做的是向站點根目錄工作發出請求是添加如下內容:
location / {
root /var/www/html;
try_files $uri /index.php$is_args$args;
}
請記住,在您的情況下,而不是/index.php$is_args$args
應該是特定於您正在使用的腳本/框架的內容。
我有同樣的錯誤,但我的問題是對主文件夾的權限。 html文件夾本身沒有權限。 在我的例子中,運行命令“chmod -R 755”解決了。 使用“-R”我還確保所有子目錄都具有相同的權限(請注意,這可能會導致安全問題,具體取決於您的情況,我的服務器是測試服務器,所以我沒有打擾)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.