說明
- 目前最優解的多專案部署在子目錄的方式
- 子目錄的路徑修正只用到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 協議》,轉載必須註明作者和本文連結