一直试图在本地设置我自己的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]“GET/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
我的码头工人。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站点。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;
}
}
提前感谢您的帮助!!!;)
由于我没有得到太多的反馈,经过多次尝试和错误,我得到了我的解决方案!!所以我把这个贴出来,以防有人有类似的问题。
这里的问题似乎是nginxsite.conf
文件。
server {
listen 80;
listen [::]:80;
index index.php index.html;
server_name laradock.localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /usr/share/nginx/html;
location / {
autoindex on; #to list file in the directory if the index file is missing
}
#### this was where i was facing the issue, the php block
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
另一个需要注意的是nginx可以有多个。配置文件,并且它不支持。类似apache的htaccess文件(需要将htaccess逻辑重新写入nginx conf.d目录中的.conf文件)
我的解决方案的完整代码可以在这个git存储库中找到
我尝试从Java服务公开端口(不同的端口#,不是只公开内部端口,等等),但没有成功。 如果我尝试将配置附加到Ignite服务,它完全不起作用。 我的最终目标是使用Docker-Compose建立一个环境,我可以在本地加入该环境进行测试,但最终将其转移到ECS/Fargate。 私人静电点火;
我在Windows中使用VSCode Docker已经有几年了,我成功地创建了一个完全工作的开发环境,没有任何问题。 最近我用WSL2建立了一个新的开发环境。使用带有WSL2容器的Docker Windows和远程连接到WSL的Windows上的VSCode,将我的所有项目、库、CLI等移动到WSL中。一切都很顺利,我喜欢我能把一切分开。 但最近我遇到了一个我无法解决的问题,我失去了调试PHP文件
方法1使用JAVA_HOME方法,我将在命令行中键入,它将说: 方法1的路径设置:https://gyazo.com/3503EF29C48175385768D8CD9B068CE4 方法2使用直接Java bin路径方法: null javac不能被识别为内部或外部命令、可操作程序或批处理文件 javac:找不到文件:first.java用法:javac
我无法在尝试设置平台后修复颤振问题,问题如下所示: https://i.stack.imgur.com/uddfn.png
WeX5 中内存有三个地方: 1 studio使用的内存,这个通过修改 studio/studio.ini 中的 -Xms40m -Xmx384m , 来控制 2 在外面启动tomcat,tomcat会去读取 apache-tomcat/bin/catalina.bat -Xms256m -Xmx1024m 3 如果是在studio中启动tomcat,tomcat使用的内存是