服务器技术

 首页 > 服务器技术 > nginx > Nginx下Wordpress的永久链接实现(301,404等)_nginx_自学

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

分享到:
【字体:
导读:
          经过多番测试,终于在nginx下实现了rewrite的功能,WrodPress的永久链接终于生效了...

其实也是很简单的方法,修改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;

#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 负载均衡 多站点共享Session_nginx...
多站点共享Session常见的作法有: •使用.net自动的状态服务(Asp.net State Service); •使用.net的Session数据库; •使用Memcached。 •使用Cookie方式实现多个站点间的共享(这种方式只限于几个站点都在同一域名的情况下); 这里我们就 演练一下 以数据库的形来存储Session,来实现多站点共享Session。 首先我们 建好...
Nginx下WordPress链接(url伪静态)301永久...
问题: 在几个blog程序中折腾的结果~ 导致url连续二次变化。这是第三次了。 nginx 通过rewrite 使用 “permanent;”参数 成301永久url重定向。 以往的url结构 http://www.jb51.net/post/199/ 现在需要的url结构 http://www.jb51.net/archives/199.html 过程: 学习nginx的配置规则,学习正则表达式(我也没接触过,学呗。)...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……