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; } } }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。