Php Nginx使用Laravel&;返回Docker内部的欢迎页面;特拉菲克
我已经为我的Laravel应用程序设置了一个自定义Nginx/PHP图像的Docker。我通过Traefik提供服务,因为我在一台机器上托管多个站点。当我加载站点时,Nginx仅返回Php Nginx使用Laravel&;返回Docker内部的欢迎页面;特拉菲克,php,laravel,docker,nginx,traefik,Php,Laravel,Docker,Nginx,Traefik,我已经为我的Laravel应用程序设置了一个自定义Nginx/PHP图像的Docker。我通过Traefik提供服务,因为我在一台机器上托管多个站点。当我加载站点时,Nginx仅返回欢迎使用Nginx页面。我已经通过nginx-T验证了我的nginx配置设置正确。我已经通过码头进入了Docker集装箱,在那里看到了我所有的文件。我已经将问题缩小到Traefik——如果我删除Traefik标签并公开一个端口,我的站点就会显示得很好。对于未使用Traefik的配置相同的站点,情况也是如此。我需要能够
欢迎使用Nginx
页面。我已经通过nginx-T
验证了我的nginx配置设置正确。我已经通过码头进入了Docker集装箱,在那里看到了我所有的文件。我已经将问题缩小到Traefik
——如果我删除Traefik标签并公开一个端口,我的站点就会显示得很好。对于未使用Traefik的配置相同的站点,情况也是如此。我需要能够使用Traefik,但让它返回我的Laravel应用程序(称为Laraview),而不是在src
中找到。谢谢你的帮助!这是我的配置:
Dockerfile
FROM justintime50/nginx-php:latest
COPY --chown=www-data:www-data ./src /var/www/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
RUN php composer.phar install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
RUN chmod -R 775 storage \
&& php artisan storage:link \
&& chmod -R 775 bootstrap/cache
version: "3.7"
services:
laraview:
build: .
restart: always
container_name: laraview
volumes:
# - ./src:/var/www/html # Only use for development
- ./src/.env:/var/www/html/.env
- ./src/storage/logs:/var/www/html/storage/logs
- ./src/storage/app/public:/var/www/html/storage/app/public
networks:
- traefik
- laraview
labels:
- traefik.enabled=true
- traefik.docker.network=traefik
- traefik.frontend.rule=Host:laraview.localhost
- traefik.port=80
env_file:
- init-db.env
depends_on:
- laraview-db
laraview-db:
image: mysql:5.7.26
restart: always
container_name: laraview-db
env_file:
- init-db.env
volumes:
- ./db:/var/lib/mysql
networks:
- laraview
ports:
- "3306:3306"
labels:
- traefik.enable=false
networks:
traefik:
external:
name: traefik
laraview:
name: laraview
nginx.conf
server {
listen 80;
index index.php index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
try_files $uri $uri/ /index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
docker compose
FROM justintime50/nginx-php:latest
COPY --chown=www-data:www-data ./src /var/www/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
RUN php composer.phar install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
RUN chmod -R 775 storage \
&& php artisan storage:link \
&& chmod -R 775 bootstrap/cache
version: "3.7"
services:
laraview:
build: .
restart: always
container_name: laraview
volumes:
# - ./src:/var/www/html # Only use for development
- ./src/.env:/var/www/html/.env
- ./src/storage/logs:/var/www/html/storage/logs
- ./src/storage/app/public:/var/www/html/storage/app/public
networks:
- traefik
- laraview
labels:
- traefik.enabled=true
- traefik.docker.network=traefik
- traefik.frontend.rule=Host:laraview.localhost
- traefik.port=80
env_file:
- init-db.env
depends_on:
- laraview-db
laraview-db:
image: mysql:5.7.26
restart: always
container_name: laraview-db
env_file:
- init-db.env
volumes:
- ./db:/var/lib/mysql
networks:
- laraview
ports:
- "3306:3306"
labels:
- traefik.enable=false
networks:
traefik:
external:
name: traefik
laraview:
name: laraview
应该是
traefik.enable=true
也
server\u name localhost
与docker compose中的主机名不匹配虽然Traefik片段不是答案,但也需要修复。原因是服务器名称不匹配。谢谢