单个域名下部署多个项目-配置 Nginx 文件夹 / 子目录访问-内部端口方式
功能实现
- 域名
http://test.local
正常访问,对应项目地址E:/Project/Test
- 域名
http://test.local/module2
正常访问,对应项目地址E:/Project/Module2
废话不说上配置
Nginx配置文件test_local.conf
server {
listen 80;
server_name test.local;
root E:/Project/Test;
index index.php index.html;
# 转发到端口
location /module2/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $proxy_host;
proxy_set_header X-Forwarded-Port $proxy_port;
proxy_pass http://127.0.0.1:8081/;
}
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;
}
}
server {
listen 8081;
server_name 127.0.0.1;
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;
}
}
module2的Laravel配置Url
.env
APP_URL=http://test.local/module2
app/Providers/AppServiceProvider
public function boot()
{
// 用于修正URL生成的链接
app('url')->forceRootUrl(config('app.url'));
}
public function register()
{
// 用于修正分页的链接
\Illuminate\Pagination\Paginator::currentPathResolver(function () {
return $this->app['url']->current();
});
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
本帖由系统于 4年前 自动加精
转发到端口
这样就可以吧
可以这样写:
你写的重定向方式为什么不需要改动laravel框架内容呢 哪种好呢 感觉还是使用2个域名吧 问题最少