单个域名下部署多个项目-配置 Nginx 文件夹 / 子目录访问-UNIX代理方式
说明
- 目前最优解的多项目部署在子目录的方式
- 子目录的路径修正只用到laravel的代理中间件
- 实现域名test.cc的路径module2指向另一个项目
test.cc
项目路径E:/Project/Test
test.cc/module2
项目路径E:/Project/Module2
nginx 配置
server {
listen 80;
server_name test.cc;
root E:/Project/Test;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# 此处重要!
# ==============================================================
location /module2/ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Prefix /module2/;
proxy_pass http://unix:/tmp/nginx_module2.socket:/;
}
# ==============================================================
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
# 此处重要!
# ==============================================================
listen unix:/tmp/nginx_module2.socket;
# ==============================================================
server_name _;
root E:/Project/Module2;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
laravel 7.2 配置
修改中间件 Http\Middleware\TrustProxies.php
protected $proxies = "*";
protected $headers = Request::HEADER_X_FORWARDED_PREFIX;
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: