Nginx Returns 内部欢迎页面 Docker 使用 Laravel & Traefik
Nginx Returns Welcome Page Inside Docker Using Laravel & Traefik
我已经为我的 Laravel 应用设置了 Docker 自定义 Nginx/PHP 图片。我通过 Traefik 为它提供服务,因为我在一台机器上托管多个站点。当我加载站点时,Nginx 仅 returns Welcome to Nginx
页面。我已经通过 nginx -T
验证我的 Nginx 配置设置正确。我已经通过终端进入 Docker 容器并在那里看到了我的所有文件。我已将问题缩小到 Traefik
- 如果我删除 Traefik 标签并公开一个端口,我的网站就可以正常显示。对于不使用 Traefik 的配置相同的站点也是如此。我需要能够使用 Traefik,但它是 return 我的 Laravel 应用程序(称为 Laraview),而不是 src
。谢谢你的帮助!这是我的配置:
Docker文件
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
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-撰写
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.enabled=true
应该是
traefik.enable=true
还有
server_name localhost;
与 docker-compose
中的主机名不匹配
我已经为我的 Laravel 应用设置了 Docker 自定义 Nginx/PHP 图片。我通过 Traefik 为它提供服务,因为我在一台机器上托管多个站点。当我加载站点时,Nginx 仅 returns Welcome to Nginx
页面。我已经通过 nginx -T
验证我的 Nginx 配置设置正确。我已经通过终端进入 Docker 容器并在那里看到了我的所有文件。我已将问题缩小到 Traefik
- 如果我删除 Traefik 标签并公开一个端口,我的网站就可以正常显示。对于不使用 Traefik 的配置相同的站点也是如此。我需要能够使用 Traefik,但它是 return 我的 Laravel 应用程序(称为 Laraview),而不是 src
。谢谢你的帮助!这是我的配置:
Docker文件
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
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-撰写
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.enabled=true
应该是
traefik.enable=true
还有
server_name localhost;
与 docker-compose