wordpress 가 nginx 서버 에 permalink 를 설정 할 때 404 의 해결 방법 을 알려 줍 니 다.
How to configure Nginx for WordPress permalinks last updated May 27, 2018 in Categories CentOS, Debian / Ubuntu, FreeBSD, Linux, Nginx, Suse, UNIX, Wordpress I switched from Apache to Nginx web server. How do I configure permalinks under WordPress blog? How can I configure Nginx for WordPress permalinks using virtual hosting?
A permalink is nothing but the web address used to link to your blog content. The URL to each blog post or cms post should be permanent and never change. Hence the name permalink. WordPress has the ability capacity to create a custom URL structure for your blog posts and archives. There are three basic types of WordPress permalinks:
Ugly: https://www.cyberciti.biz/faq/?p=2284 Pretty using mod_rewrite: https://www.cyberciti.biz/faq/bash-for-loop/ Almost pretty using PHP PATHINFO: https://www.cyberciti.biz/faq/index.php/bash-for-loop/ In the Settings > Permalinks panel, you can choose one of the more common permalink structures as follows:
Fig.01: configure Nginx for WordPress permalinks : Choosing your permalink structure Fig.01: Configure Nginx for WordPress permalinks : Choosing your permalink structure How to configure Nginx for WordPress permalinks (“Pretty” permalinks) Edit your nginx.conf file using a text editor such as nano command or vim command, run: $ sudo vi /etc/nginx/site-enabled/cyberciti.biz.conf
Edit/add/append the following location block within the server block:
location / {
try_files $uri $uri/ /index.php?$args;
}
If your WordPress blog is in /faq/ sub-directory, try :
#
note path to /faq/index.php
#
location /faq/ {
try_files $uri $uri/ /faq/index.php?$args;
}
Save and close the file. Restart/reload your nginx server, run: $ sudo systemctl reload nginx
OR $ sudo /usr/sbin/nginx -s reload
Here is my sample config file:
Upstream to abstract backend connection(s) for PHP.
upstream php {
server unix:/run/php/php7.0-fpm.sock;
}
server {
server_name www.cyberciti.biz;
root /var/www/html;
location /faq/ {
try_files $uri $uri/ /faq/index.php?$args;
}
#Add trailing slash to */wp-admin requests.
rewrite /faq/wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
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;
}
Pass all .php files onto a php-fpm/php-fcgi server.
index index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
This is a robust solution for path info security issue and works with “cgi.fix_pathinfo = 1” in /etc/php.ini (default)
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php;
}
}
The above config is from this site itself.
Nginx and WordPress permalinks full example Here is config for my personal blog that runs on Ubuntu Linux 16.04 LTS along with PHP 7.x.x:
Upstream to abstract backend connection(s) for PHP
upstream php {
server unix:/run/php/php7.0-fpm.sock;
}
## my server ip address ##
server {
set_real_ip_from 10.147.164.1;
real_ip_header X-Forwarded-For;
listen 10.147.164.3:80;
server_name theos.in www.theos.in;
root /home/lighttpd/theos.in/http;
## WordPress Perm links config ##
location / {
try_files $uri $uri/ /index.php?$args;
}
## Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
## Deal with sitemap wordpress plugin urls ##
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml$ "/index.php?xml_sitemap=params=$2" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html$ "/index.php?xml_sitemap=params=$2;html=true" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;
# Directives to send expires headers and turn off 404 error logging.
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;
}
## Okay, Pass all .php files onto a php-fpm/php-fcgi server.
index index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
## Setting works on Ubuntu/Debian Linux
### This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default)
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php;
}
}
Posted by: Vivek Gite The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
3가지 방법으로 WordPress에서 AJAX 사용여기서 우리는 AJAX를 사용하여 가장 많이 사용되는 3가지 도구를 사용하여 데이터를 가져오는 것을 볼 것입니다. 활성 테마 폴더의 루트에 있는 functions.php 파일에 함수와 두 개의 후크를 생성하여 시작하...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.