How to install WordPress alongside Laravel on Nginx with pretty permalinks (SEO-friendly URLs)?

前端 未结 1 2007
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 20:47

I have a Laravel site running on Nginx, and it\'s fine.

It has a normal folder structure like:

/app
/public
/vendor
...

The /

相关标签:
1条回答
  • 2020-12-09 21:08

    You route everything to laravel in your / location, but you need to write everything /blog/ to the index.php in /blog/index.php:

    location /blog/ {
        try_files $uri $uri/ @wordpress;
    }
    
    location @wordpress {
        rewrite /blog/ /blog/index.php;
    }
    

    Then your php handler needs path info support:

    location ^/blog/index.php(/.*)?$ {
        fastcgi_split_path_info ^(/blog/index.php)(/.*)$;
        fastcgi_pass   127.0.0.1:9123;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        include fastcgi_param;
    }
    

    Turn on debug verbosity for error log if this doesn't work and post log info.

    UPDATE: Note from original question asker:

    Here is a snippet of my new Nginx config, which seems to work for these URLs: /, /blog, /course, /blog/innately-happy, and /blog/sitemap_index.xml

    ...
    error_log /Users/myuser/code/myproject/storage/logs/nginx_error.log debug;
    
     # Point index to the Laravel front controller.
    index           index.php;
    
    location /blog/ {
        try_files $uri $uri/ @wordpress;
    }
    
    location @wordpress {
        rewrite /blog/ /blog/index.php;
    }
    
    location ^/blog/index.php(/.*)?$ {
        fastcgi_split_path_info ^(/blog/index.php)(/.*)$;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        include fastcgi_params;
    }
    
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    ...
    
    0 讨论(0)
提交回复
热议问题