繁体   English   中英

在Nginx中设置Wordpress和Rails

[英]Setting up Wordpress and Rails in Nginx

我为Rails应用程序设置了nginx,它一直在为我工作。 现在我想将我的Wordpress博客从blog.website.com移到website.com/blog ,因此网页抓取工具将其视为网站的一部分。

我在我的Rails应用程序的public/目录中创建了一个符号链接,并将以下内容添加到我的nginx配置中:

# Rails server
server {
    root /project/path/current/public;
    server_name project.com;
    passenger_enabled on;
    rails_env production;
    client_max_body_size 20m;

    if ($http_x_forwarded_proto != 'https') {
        return 301  https://$host$request_uri;
    }

    location /blog {
        index    index.html  index.php;
        try_files $uri $uri/ /blog/index.php?q=$uri&$args;

        if (!-e $request_filename) {
            rewrite ^.+?(/blog/.*.php)$ $1 last;
            rewrite ^ /blog/index.php last;
        }
    }

    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_intercept_errors on;
    include fastcgi_params;
    fastcgi_index  index.php;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
}

这非常有效。 但我想做的是跳过符号链接部分。 我想让nginx直接路由到wordpress目录。 我尝试将/blog块更改为:

location ^~ /blog {
  root /home/ubuntu/apps/blog;
  index    index.html  index.php;
  try_files $uri $uri/ /blog/index.php?q=$uri&$args;

  if (!-e $request_filename) {
    rewrite ^.+?(/blog/.*.php)$ $1 last;
    rewrite ^ /blog/index.php last;
  }
}

这是有效的,因为我正确地被重定向到wordpress文件夹但我的服务器不知道如何处理php文件并将它们作为文件下载发送到我的浏览器。

我尝试在/blog位置嵌套\\.php$位置,但是会导致404错误。

以下部分有什么问题以及如何解决?

location ^~ /blog {
  root /home/ubuntu/apps/blog;
  index    index.html  index.php;
  try_files $uri $uri/ /blog/index.php?q=$uri&$args;

  if (!-e $request_filename) {
    rewrite ^.+?(/blog/.*.php)$ $1 last;
    rewrite ^ /blog/index.php last;
  }

  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_intercept_errors on;
    include fastcgi_params;
    fastcgi_index  index.php;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
  }
}

我没有修复问题的片段,但我设法通过使用两个server块而不使用符号链接来解决nginx配置问题。

server {
    location / {
        proxy_pass http://localhost:82/;
    }

    location /blog {
        root /var/proj/blog/current;
        fastcgi_intercept_errors on;
        include fastcgi_params;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
}
# Rails server                                                                                                                                                                                                                             
server {
    listen 82;
    root /var/proj/site/current/public;
    server_name site.com;
    passenger_enabled on;
    rails_env staging;
    client_max_body_size 20m;

    # other configuration
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM