403使用nginx、PHP-FPM和docker的PHP文件出错
我将docker compose与以下内容一起使用403使用nginx、PHP-FPM和docker的PHP文件出错,php,nginx,docker,http-status-code-403,Php,Nginx,Docker,Http Status Code 403,我将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: -
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
,我在docker compose中有一个403错误和以下日志:
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尝试从指定的根目录提供静态文件李>
默认情况下,索引文件是index.html
,您不会覆盖此设置。这就是为什么当您添加index.html
时,它开始正常工作的原因李>
默认情况下,目录索引是禁止的,这是nginx在索引文件丢失时尝试执行的操作。所以你得到了403的回复,我在你的日志中清楚地看到了这一点
如果您使用/index.php
要请求站点根目录工作,您应该添加以下内容:
location / {
root /var/www/html;
try_files $uri /index.php$is_args$args;
}
请记住,在您的例子中,php$is_args$args
应该是特定于您所使用的脚本/框架的内容,而不是/index.php$is_args$args