我使用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"
我已经尝试过在其他Q& A(例如here)中找到的建议,但我无法让它发挥作用。
答案 0 :(得分:1)
从您的日志中我发现您正在尝试访问/
位置。而且我没有在你的nginx配置中看到会拦截这种请求的条目。所以我假设在这种情况下跟随:
/
nginx尝试的请求提供来自指定root
的静态文件; index.html
,您不会覆盖此设置。这就是为什么当你添加index.html
; 如果您使用/index.php
对网站root工作提出请求应该做的是添加类似的内容:
location / {
root /var/www/html;
try_files $uri /index.php$is_args$args;
}
请注意,在您的情况下,{而不是/index.php$is_args$args
应该是您正在使用的脚本/框架的特定内容。