Nginx下Wordpress的永久鏈接實(shí)現(xiàn)(301,404等)
其實(shí)也是很簡(jiǎn)單的方法,修改nginx.conf文件,加入以下內(nèi)容:
location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
重啟nginx就可以了。
以下是我的配置文件實(shí)例:
www# cat nginx.conf
user www www;
worker_processes 10;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/local/www/nginx;
index index.php index.html index.htm;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/nginx$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
- Nginx實(shí)現(xiàn)404頁(yè)面的方法小結(jié)
- Nginx中404頁(yè)面的配置及AJAX請(qǐng)求返回404頁(yè)面的方法
- Nginx+CI框架出現(xiàn)404錯(cuò)誤怎么解決
- Nginx服務(wù)器中配置404錯(cuò)誤頁(yè)面時(shí)一些值得注意的地方
- 一個(gè)等號(hào)引發(fā)的血案(談Nginx正確的404配置)
- Nginx中定義404頁(yè)面并且返回404狀態(tài)碼的正確方法
- PHP統(tǒng)計(jì)nginx訪問(wèn)日志中的搜索引擎抓取404鏈接頁(yè)面路徑
- NGINX下配置404錯(cuò)誤頁(yè)面的方法分享
- 為Nginx自定義404,502錯(cuò)誤頁(yè)面的方法
- NGINX服務(wù)器配置404錯(cuò)誤頁(yè)面轉(zhuǎn)向的方法
相關(guān)文章
nginx支持.htaccess文件實(shí)現(xiàn)偽靜態(tài)的方法分享
這篇文章主要介紹了nginx支持.htaccess文件實(shí)現(xiàn)偽靜態(tài)的方法分享,需要的朋友可以參考下2015-01-01
nginx?攔截指定ip訪問(wèn)指定url的實(shí)現(xiàn)示例
本文主要介紹了nginx?攔截指定ip訪問(wèn)指定url的實(shí)現(xiàn)示例,使用$http_x_forwarded_for變量來(lái)獲取客戶端的真實(shí)IP地址,感興趣的可以了解一下2024-12-12
Nginx轉(zhuǎn)發(fā)丟失cookie表現(xiàn)形式及解決方案
本文主要介紹了Nginx轉(zhuǎn)發(fā)丟失cookie表現(xiàn)形式及解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01
nginx日志切割定時(shí)任務(wù)的實(shí)現(xiàn)
Nginx日志切割能有效管理日志,便于查詢、控制存儲(chǔ)空間、提高處理效率、方便備份與歸檔,減少數(shù)據(jù)丟失風(fēng)險(xiǎn),實(shí)現(xiàn)方法包括重命名日志文件、編寫定時(shí)日志腳本和設(shè)置crontab定時(shí)任務(wù)2024-11-11
Nginx服務(wù)器中的模塊編寫及相關(guān)內(nèi)核源碼初探
這篇文章主要介紹了Nginx服務(wù)器中的模塊編寫及相關(guān)源碼初探,文中以一個(gè)簡(jiǎn)單的Hello world模塊的編寫來(lái)深入分析Nginx內(nèi)核所用到的基礎(chǔ)函數(shù),需要的朋友可以參考下2015-12-12
詳解Nginx服務(wù)器的配置中開(kāi)啟文件Gzip壓縮的方法
這篇文章主要介紹了Nginx服務(wù)器的配置中開(kāi)啟文件Gzip壓縮的方法,可以對(duì)CSS和JavaScript以及各種圖片等web傳輸?shù)奈募M(jìn)行壓縮,需要的朋友可以參考下2016-01-01
Nginx反向代理proxy_cache_path directive is not allowed錯(cuò)誤解決方法
這篇文章主要介紹了Nginx反向代理proxy_cache_path directive is not allowed錯(cuò)誤解決方法,需要的朋友可以參考下2015-04-04
Nginx基礎(chǔ)location語(yǔ)法及功能配置實(shí)例
這篇文章主要為大家介紹了Nginx基礎(chǔ)location語(yǔ)法及功能以及配置實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-03-03

