docker php 乱码,用PHP在Docker问题中设置lemp

博主在本地配置LEMP堆栈时遇到问题,Nginx和PHP各自运行正常,但尝试将两者集成时遇到了403禁止错误。错误日志显示目录访问被禁止。Docker镜像是PHP 7.1-fpm-alpine和Nginx的alpine版本。配置文件包括docker-compose.yml和nginx的site.conf。博主提供了详细的配置信息,并寻求解决方案。
摘要由CSDN通过智能技术生成

一直在尝试在本地设置自己的LEMP堆栈,nginx和php似乎都单独工作得很好,但是尝试在nginx中集成php失败了…!!!!获取错误

403禁止

nginx错误日志:

2018/07/22 12:06:48[错误]9 9:/1目录索引/usr/share/nginx/html/“被禁止,客户端:172.19.0.4,服务器:localhost,请求:“get/http/1.1”,主机:“laradock.localhost:8000”

172.19.0.4-[22/jul/2018:12:06:48+0000]“获取/http/1.1”403 571“-”Mozilla/5.0(x11;Linux x86_64)AppleWebKit/537.36(khtml,类似gecko)Chrome/67.0.3396.99 Safari/537.36“”172.19.0.1“

一直在使用下面的Docker图像版本:

PHP_TAG=7.1-fpm-alpine

NGINX_TAG=alpine

我的docker-compose.yml文件

version: "2"

services:

php:

image: php:$PHP_TAG

# restart: always

container_name: "${PROJECT_NAME}_php"

environment:

PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025

DB_HOST: $DB_HOST

DB_USER: $DB_USER

DB_PASSWORD: $DB_PASSWORD

DB_NAME: $DB_NAME

DB_DRIVER: $DB_DRIVER

volumes:

- /var/www/ro_www/src/sample_site/:/usr/share/nginx/html

nginx:

image: nginx:$NGINX_TAG

container_name: "${PROJECT_NAME}_nginx"

depends_on:

- php

# - mysqld

environment:

NGINX_STATIC_CONTENT_OPEN_FILE_CACHE: "off"

NGINX_ERROR_LOG_LEVEL: debug

NGINX_BACKEND_HOST: php

NGINX_SERVER_ROOT: /var/www/html/

# NGINX_DRUPAL_FILE_PROXY_URL: http://example.com

volumes:

- /var/www/ro_www/src/sample_site/:/usr/share/nginx/html

- ./config/site.conf:/etc/nginx/conf.d/site.conf:ro

# - ./etc/ssl:/etc/ssl

# ports:

# - "8000:80"

# - "3000:443"

labels:

- 'traefik.backend=nginx'

- 'traefik.port=80'

- 'traefik.frontend.rule=Host:${PROJECT_BASE_URL}'

mailhog:

image: mailhog/mailhog

container_name: "${PROJECT_NAME}_mailhog"

labels:

- 'traefik.backend=mailhog'

- 'traefik.port=8025'

- 'traefik.frontend.rule=Host:mailhog.${PROJECT_BASE_URL}'

adminer:

container_name: "${PROJECT_NAME}_adminer"

image: wodby/adminer:$ADMINER_TAG

environment:

ADMINER_SALT: adminer-salt

volumes:

- /var/www/ro_www/src/sample_site/adminer/:/usr/share/nginx/html

labels:

- 'traefik.backend=adminer'

- 'traefik.port=9000'

- 'traefik.frontend.rule=Host:adminer.${PROJECT_BASE_URL}'

portainer:

image: portainer/portainer

container_name: "${PROJECT_NAME}_portainer"

command: --no-auth -H unix:///var/run/docker.sock

volumes:

- /var/run/docker.sock:/var/run/docker.sock

labels:

- 'traefik.backend=portainer'

- 'traefik.port=9000'

- 'traefik.frontend.rule=Host:portainer.${PROJECT_BASE_URL}'

traefik:

image: traefik

container_name: "${PROJECT_NAME}_traefik"

command: -c /dev/null --web --docker --logLevel=INFO

ports:

- '8000:80'

- '8080:8080' # Dashboard

volumes:

- /var/run/docker.sock:/var/run/docker.sock

nginx site.conf文件如下:

server {

listen 80;

server_name nginx;

#charset koi8-r;

#access_log /var/log/nginx/host.access.log main;

location / {

root /usr/share/nginx/html;

index index.html index.htm index.php;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

# error_page 500 502 503 504 /50x.html;

# location = /50x.html {

# root /usr/share/nginx/html;

# }

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

#root html;

#fastcgi_pass php:9000;

fastcgi_pass unix:/var/run/php-fpm.sock;

fastcgi_index index.php;

#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

location ~ /\.ht {

deny all;

}

}

提前感谢您的帮助!!!!;)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值