使用nginx的Laravel和WordPress集成路由

使用nginx的Laravel和WordPress集成路由,wordpress,laravel,nginx,laravel-routing,laravel-5.2,Wordpress,Laravel,Nginx,Laravel Routing,Laravel 5.2,我正在Laravel 5.2中开发web应用程序。我有现有的WordPress网站。所以,我想将Laravel与WordPress集成。WordPress应用程序有静态页面。我的根目录中有两个单独的目录,分别是Laravel和WordPress 拉拉普 wpApp 我想将wpApp设置为默认应用程序。所以,当用户单击登录按钮时,用户将被重定向到laraApp。我想要www.example.com上的wapp和www.example.com/laraApp上的laraApp。我有nginxweb服

我正在Laravel 5.2中开发web应用程序。我有现有的WordPress网站。所以,我想将Laravel与WordPress集成。WordPress应用程序有静态页面。我的根目录中有两个单独的目录,分别是Laravel和WordPress

  • 拉拉普
  • wpApp
  • 我想将wpApp设置为默认应用程序。所以,当用户单击登录按钮时,用户将被重定向到laraApp。我想要www.example.com上的wapp和www.example.com/laraApp上的laraApp。我有nginxweb服务器正在运行。那么我的nginx配置文件应该是什么呢

    当前nginx配置文件为:

    server {
        listen 80;
        root /var/www/root/wpApp;
        index index.php index.html index.htm;
        server_name www.example.com;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
        # rewrite rules for laravel routes
            location /laraApp {
            rewrite ^/laraApp/(.*)$ /laraApp/public/index.php?$1 last;
        }
        location ~ \.php$ {
            try_files $uri /index.php =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
    
    在这里,可以使用url www.example.com/laraApp/public访问我的Laravel应用程序/ 我想使用www.example.com/laraApp访问它


    谢谢。

    如果每个应用程序的基本URI不重叠,配置会更简单。但是考虑到问题的限制,您必须为配置中每个应用程序的PHP部分使用两个不同的文档根

    当您将一个应用程序放置在
    /
    中时,另一个应用程序通过使用嵌套的位置块保持独立。注意使用
    ^ ~
    修饰符来阻止第一个PHP块处理Laravel请求


    我目前不在测试系统中,因此没有对上述内容进行语法检查或测试。

    如果每个应用程序的基本URI没有重叠,那么配置会更简单。但是考虑到问题的限制,您必须为配置中每个应用程序的PHP部分使用两个不同的文档根

    当您将一个应用程序放置在
    /
    中时,另一个应用程序通过使用嵌套的位置块保持独立。注意使用
    ^ ~
    修饰符来阻止第一个PHP块处理Laravel请求

    我目前不在我的测试系统中,因此上面的内容没有经过语法检查或测试

    index index.php index.html index.htm;
    
    root /var/www/root/wpApp;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ~ \.php$ {
        try_files $uri /index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
    
    location ^~ /laraApp {
        rewrite ^/laraApp(.*)$ /laraApp/public$1 last;
    }
    
    location ^~ /laraApp/public {
        root /var/www/root;
    
        try_files $uri $uri/ /laraApp/public/index.php?$query_string;
    
        location ~ \.php$ {
            try_files $uri /laraApp/public/index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
    }