用于反向代理php-fpm的thinkphp项目,内置rewrite规则。
463
自带配置文件生成功能,用于快速的部署多个访问路径(是指nginx中的一个“location”,本项目中成为context)。
通过在创建docker容器的时候传递环境变量来设置context,环境变量的命名支持NGINX_CONTEXT,以及NGINX_CONTEXT_1两种格式(第二种格式的1是指数字序号,最多支持到20)。
每个环境变量的值是以竖线分割的字符串,其格式及含义为“type|context|path|host”,其中
以下是创建docker容器的命令行示例:
docker run -d -e NGINX_CONTEXT_1=static\|/\|/var/www/html --name nginx chingo/nginx-thinkphp
支持4种context的配置:
推荐使用docker-compose来部署。
version: '3.5'
services:
nginxv2:
container_name: nginxv2
image: e499471b0912
environment:
NGINX_CONTEXT: static|/|/var/www/html
NGINX_CONTEXT_1: thinkphp|/api|/var/www/html/public|agent-php
NGINX_CONTEXT_2: http|/movie|http://192.168.104.35:8080/movie
NGINX_CONTEXT_8: vue|/dashboard|/var/www/dashboard
restart: always
则docker容器/etc/nginx/conf.d/目录下将生成default.conf,内容如下
server {
listen 80 default_server;
server_name _;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
##############################################
# CONTEXT static|/|/var/www/html
location / {
alias /var/www/html;
index index.html;
}
##############################################
# CONTEXT thinkphp|/api|/var/www/html/public|agent-php
location /api {
alias /var/www/html/public;
try_files $uri $uri/ @thinkphp1;
client_max_body_size 40m;
client_body_buffer_size 128k;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass agent-php;
}
}
location @thinkphp1 {
rewrite /api/(.*)$ /api/index.php?s=/$1 last;
}
##############################################
# CONTEXT http|/movie|http://192.168.104.35:8080/movie
location /movie {
proxy_pass http://192.168.104.35:8080/movie;
expires off;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
##############################################
# CONTEXT vue|/dashboard|/var/www/dashboard
location /dashboard {
alias /var/www/dashboard;
try_files $uri $uri/ /index.html;
index index.html;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
access_log off;
log_not_found off;
}
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
if ($request_method !~ ^(GET|HEAD|POST|OPTIONS)$ ) {
return 444;
}
}
Content type
Image
Digest
Size
6.6 MB
Last updated
over 7 years ago
docker pull chingo/nginx-thinkphp