我已经在 Docker 上使用 nginx、php 7.4 fpm 和 mysql 8 设置了 Laravel。
我是 Docker 新手,我一直在学习几个教程,并以某种方式设法在单独的容器中运行每个服务,并在不同的目录中运行代码。
只有索引页面有效,但其他任何路线都无效。
docker-compose.yml
version: '3'
services:
nginx:
build:
context: ./nginx
volumes:
- ../laravelproject:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/sites/:/etc/nginx/sites-available
- ./nginx/conf.d/:/etc/nginx/conf.d
depends_on:
- php-fpm
ports:
- "80:80"
- "443:443"
php-fpm:
build:
context: ./php-fpm
volumes:
- ../laravelproject:/var/www
- ../laravelproject/serve_config/custom.ini:/usr/local/etc/php/conf.d/custom.ini
database:
build:
context: ./database
environment:
- MYSQL_DATABASE=mydb
- MYSQL_USER=myuser
- MYSQL_PASSWORD=secret
- MYSQL_ROOT_PASSWORD=docker
volumes:
- ./database/data.sql:/docker-entrypoint-initdb.d/data.sql
command: ['--default-authentication-plugin=mysql_native_password']
站点文件夹中的默认配置
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name localhost;
root /var/www;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location /.well-known/acme-challenge/ {
root /var/www/letsencrypt/;
log_not_found off;
}
}
conf.d 文件夹中的默认配置
upstream php-upstream {
server php-fpm:9000;
}
索引页面工作正常,但是当我添加新路由时,它显示来自 nginx 的 404。
我对 docker 没有太多经验,我一直在遵循几个教程来设置它。
Thanks
我找到了解决方法。
我改变了根并且它起作用了。
root /var/www/public
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)