Rails 和 Wordpress 配合 Nginx 配置

由于项目需要公司主页需要使用 Wordpress,但是后台管理还是使用的 Rails 程序。 所以需要 nginx 修改配置才能达到效果。

Nginx 配置如下

Wordpress 是配置在 http://abc.com/www 子路径下。需要在 Rails 的主页处理的时候,自动跳转至此 URL。 wordpress 的服务器文件是放在 /home/deploy/apps/abc_home/www 下面。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
server {
        listen 443;
        server_name  abc.com www.abc.com;
        ssl on;
        ssl_certificate   /etc/nginx/cert/xxx.pem;
        ssl_certificate_key  /etc/nginx/cert/xxx.key;
        ssl_session_timeout 5m;
        ssl_ciphers XXX;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        passenger_enabled on;
        passenger_min_instances 6;
        passenger_max_request_queue_size 300;
        rails_env    production;
        root         /home/deploy/apps/abc/current/public;


       location = /www { rewrite ^ /www/ last; }

       location ^~ /www/ {
          root /home/deploy/apps/abc_home/;
          index index.php;

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

          location ~ \.php(?|$) {
            include /etc/nginx/fastcgi_params;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
         }
      }
}

server {
        listen 80;
        server_name  abc.com www.abc.com;
        return 301 https://$server_name$request_uri;
}

评论