質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

Q&A

2回答

3116閲覧

Nginx WordPressのパーマリンク設定でエラー

ruby_0ct

総合スコア57

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

0グッド

0クリップ

投稿2017/10/18 02:11

編集2022/01/12 10:55

nginxを勉強中です。WordPressのパーマリンク設定を「月と投稿名」にしたのですが、404でエラーになります。

おそらく、nginx.confの設定が原因だと思うのですが、どのように設定すればいいか調べてもイマイチわかりません。教えていただけると幸いです。

nginx.conf

server { listen 80; server_name ドメイン名/blog; return 301 https://ドメイン名/blog$request_uri; } server { listen 443 ssl; server_name ドメイン名/blog; ssl_certificate ****; ssl_certificate_key ****; access_log /var/log/nginx/blog.access.log main; location / { root /var/www/html/blog; index index.html index.htm index.php; } location ~ .php$ { root /var/www/html/blog; fastcgi_split_path_info ^(.+.php)(.*)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_read_timeout 300; } # WordPressの設定 location @wordpress { fastcgi_index index.php; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_param SCRIPT_FILENAME /var/www/html/blog/index.php; include fastcgi_params; } }

###追記1 02:53
ay03さん
ご回答ありがとうございます。
とりあえず参考にしながら修正してみたところエラー表示が変わり、File not found.となりました。

サーバ側は、単にアドレス通りにディレクトリを読んでいるのでこのエラーに変わったんだと思いますが、原因はnginx.confの設定に間違いないと思います。

WordPressは、作成したサイトのブログページ部分のみに導入しているので、バーチャルホストを利用して設定しています。

一応、nginx.conf全文を載せておきます。

user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name ドメイン名; return 301 https://ドメイン名$request_uri; } server { listen 443 ssl; server_name ドメイン名; ssl_certificate ***; ssl_certificate_key ***; charset UTF-8; location / { try_files $uri $uri/ /index.php?$query_string; root /var/www/html; index index.html index.html index.php; if ( -f $request_filename ) { expires 30d; break; } if (!-e $request_filename) { rewrite ^.+?(/.*.php)$ $1 last; rewrite ^ /index.php last; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ .php$ { root /var/www/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } # ブログ server { listen 80; server_name ドメイン名/blog; return 301 https://ドメイン名/blog$request_uri; } server { listen 443 ssl; server_name ドメイン名/blog; ssl_certificate ***; ssl_certificate_key ***; access_log /var/log/nginx/blog.access.log main; location / { root /var/www/html/blog; index index.html index.htm index.php; try_files $uri $uri/ /index.php?$query_string; if ( -f $request_filename ) { expires 30d; break; } if (!-e $request_filename) { rewrite ^.+?(/.*.php)$ $1 last; rewrite ^ /index.php last; } } location ~ .php$ { root /var/www/html/blog; fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; include fastcgi_params; fastcgi_read_timeout 300; } location ~* ^.+.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; } location ~ .php$ { try_files $uri =404; fastcgi_split_path_info ^(.+.php)(.*)$; fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PAHT_INFO $fastcgi_script_name; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; } location ^~ /phpmyadmin { alias /var/www/phpmyadmin; index index.php index.html; location ~ ^/phpmyadmin/(.+.php)$ { alias /var/www/phpmyadmin/$1; fastcgi_index index.php; fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } # WordPressの設定 location @wordpress { fastcgi_index index.php; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_param SCRIPT_FILENAME /var/www/html/blog/index.php; include fastcgi_params; } } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

設定ファイルを拝見したところ、rewriteの部分に問題がありそうな気がします。下記の部分をコメントアウトしてみてはいかがでしょうか?

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

あと気になった点がありまして、 server_nameディレクティブはホスト名を指定するものなので、
server_name ドメイン名/blog;というのはちょっと不思議に見えます。

もし書くとしたら

server { server_name ドメイン名; location /blog { ~wordpress向けの設定 }

というのが正攻法?かなと思います。

投稿2017/10/31 04:16

newbiemstr

総合スコア43

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

突っ込み所があるかもしれないですが、NginxでSSLを使ってWordPressとphpMyAdminを動かしてる設定ファイルの例です。
パーマリンクがカスタム構造でも問題ないはずです。
参考になるかどうか分かりませんが、上手く読み替えて試してみてください。

/etc/nginx/conf.d/nginx.conf

server { listen 80; server_name 192.168.100.100; root /var/www/html; index index.php index.html index.htm; listen 443 default ssl; ssl on; ssl_certificate /etc/pki/tls/certs/server.crt; ssl_certificate_key /etc/pki/tls/certs/server.key; location / { try_files $uri $uri/ /index.php?$query_string; root /var/www/html; index index.html index.html index.php; if ( -f $request_filename ) { expires 30d; break; } if (!-e $request_filename) { rewrite ^.+?(/.*.php)$ $1 last; rewrite ^ /index.php last; } } location ~ .php$ { fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; include fastcgi_params; } location ~* ^.+.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; } location ~ .php$ { try_files $uri =404; fastcgi_split_path_info ^(.+.php)(.*)$; fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PAHT_INFO $fastcgi_script_name; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; } location ^~ /phpmyadmin { alias /var/www/phpmyadmin; index index.php index.html; location ~ ^/phpmyadmin/(.+.php)$ { alias /var/www/phpmyadmin/$1; fastcgi_index index.php; fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }

投稿2017/10/19 16:00

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問