首页 > 服务器 > Web服务器 > 正文

Nginx下Wordpress的永久链接实现(301,404等)

2024-09-01 13:45:07
字体:
来源:转载
供稿:网友

其实也是很简单的方法,修改nginx.conf文件,加入以下内容:

复制代码 代码如下:


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就可以了。

以下是我的配置文件实例:

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;

#pidlogs/nginx.pid;

events {
worker_connections 1024;
}

http {
includemime.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;

sendfileon;
#tcp_nopushon;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen80;
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 ;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ /.php$ {
roothtml;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/nginx$fastcgi_script_name;
includefastcgi_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 {
# listen8000;
# listensomename:8080;
# server_name somename alias another.alias;

# location / {
#root html;
#index index.html index.htm;
# }
#}

# HTTPS server
#
#server {
# listen443;
# server_name localhost;

# sslon;
# ssl_certificatecert.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;
# }
#}
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表