容器化部署laravel框架的php项目
参考:
server {
listen 80;
server_name localhost;
root /var/www/html/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$query_string;
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?s=$1 last;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
# root /var/www/html/public; # 忽略这个容器php文件 File not found
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}
docker-composer.yml
version: '3'
networks:
nginx-php-network:
services:
web:
image: nginx:latest
ports:
- "8081:80"
volumes:
- ./nginx-config:/etc/nginx/conf.d
- ./:/var/www/html
depends_on:
- php
networks:
- nginx-php-network
restart: always # 指定容器退出后的重启策略为始终重启
php:
image: webdevops/php-nginx:7.3-alpine # 可替换php-7.3.33-fpm-alpine3.14:v1
ports:
- "9000:9000"
restart: always
networks:
- nginx-php-network
volumes:
- ./:/var/www/html