NginxでWordPressをサブディレクトリに設置

NginxでWordPressをサブディレクトリに設置するときの手順。

http://ドメイン/blogでアクセスした場合、ブログとして WordPressを表示させたい。Apacheなら簡単ですが、今回は時間がかかったので、Nginxの設定を書いておく。

環境:
Amazon Linux
Nginx1.8
PHP 7.0.3

今回の設定例は以下。

URL ディレクトリ メモ
http://owani.net /var/www/html/ ドキュメントルート
http://owani.net/blog /var/www/html/blog WordPress本体

/etc/nginx/nginx.conf

1.server {
2.        listen       80;
3.        server_name  owani.net;
4.        root         /var/www/html;
5.
6.        location / {
7.               try_files $uri $uri/ index.html index.php;
8.        }
9.
10.        location @wp {
11.           rewrite ^/blog(.*) /blog/index.php?q=$1;
12.        }
13.        location ^~ /blog {
14.           root /var/www/html;
15.           index index.php index.html index.htm;
16.           try_files $uri $uri/ @wp;
17.
18.           location ~ \.php$ {
19.             include fastcgi_params;
20.             fastcgi_param SCRIPT_FILENAME $request_filename;
21.             fastcgi_pass 127.0.0.1:9000;
22.           }
23.        }
24.    }

これでいけました。

参考サイト:
Nginx – wordpress in a subdirectory, what data should be passed?

[Sponsored Links]







  • このエントリーをはてなブックマークに追加
[Sponsored Links]