单个域名下部署多个项目-配置 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/module2app/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 协议》,转载必须注明作者和本文链接
                      本帖由系统于 5年前 自动加精
            
                 
           悠悠山雨 的个人博客
 悠悠山雨 的个人博客
         
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
                     
                     
             
             
           
           关于 LearnKu
                关于 LearnKu
               
                     
                     
                     粤公网安备 44030502004330号
 粤公网安备 44030502004330号 
 
推荐文章: