Laravel和WordPress nginx配置

时间:2014-08-11 21:17:00

标签: php wordpress laravel nginx laravel-4

enter image description here 我想在/ public / cms的Laravel 4项目中安装WordPress,我不需要通过浏览器访问WordPress页面,但我需要发布到WordPress路由以更新WP内容(表单)在laravel内。

我尝试更新我的vhosts文件以匹配答案:How to install WordPress alongside Laravel on Nginx with pretty permalinks (SEO-friendly URLs)?

但这会导致重定向循环。

这是我的nginx vhost文件:

server {
listen 80;
server_name laravel.mylifemysmile.org;
root /var/www/mylifemysmile/public;

    # Point index to the Laravel front controller.
index           index.php;

location /cms/ {
    try_files $uri $uri/ @wordpress;
}

location @wordpress {
    rewrite /cms/ /cms/index.php;
}

location ^/cms/index.php(/.*)?$ {
    fastcgi_split_path_info ^(/cms/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$query_string;
}

# Remove trailing slash to please routing system.
if (!-d $request_filename) {
        rewrite     ^/(.+)/$ /$1 permanent;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
   # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;
 }
}

更新

这是新的nginx vhost(服务器块)文件:

server {
listen 80;
server_name laravel.mylifemysmile.org;
root /var/www/mylifemysmile/public;

    # Point index to the Laravel front controller.
index           index.php;

location / {
    try_files $uri $uri/ /index.php$query_string @laravel;
}

# Remove trailing slash to please routing system.
if (!-d $request_filename) {
        rewrite     ^/(.+)/$ /$1 permanent;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    set $php_root /var/www/mylifemysmile/public;
    if ($request_uri ~ /cms/) {
        # ok, this line is a bit confusing, be aware
        # that path to /cms/ is already in the request
        # so adding a trailing /cms here will
        # give a "no input file" message
        set $php_root /var/www;
    }
   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
   # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param                   SCRIPT_FILENAME $php_root$fastcgi_script_name;
 }
 # now wordpress, remember this lives in a sibling directory of the main app
 location ~ /cms/ {
    try_files $uri $uri/ /index.php$args;
    # again, this might look a bit weird,
    # but remember that root directive doesn't drop
    # the request prefix, so /cms is appended at the end
    root /var/www;
    if (!-d $request_filename)
    {
        rewrite ^/(.*)/$ /$1 permanent;
    }
  }
}

我将wordpress从laravel / public移到了与laravel相同级别的自己的文件夹中。我现在可以在laravel网站上访问WordPress内容(包括图片),但仍然无法访问wordpress仪表板。

0 个答案:

没有答案