hooyes 灵感纵容非凡

一个关于Wordpress完整的Nginx配置例子

2017-09-15
hooyes

描述

这是一个关于Wordpress完整的Nginx配置例子,配置有url rewrite 。

配置

基本配置

server {
        listen       80;
        server_name  www.hooyes.net;
        #include restrictions.conf;
        
        location / {
            # 简单地址重写
            #if (!-e $request_filename) {
            #    rewrite (.*) /index.php;
            #}
            # 完整地址重写 
            rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last;
            if (!-e $request_filename) {
                rewrite ^.+/?(/wp-.*) $1 last;
                rewrite ^.+/?(/.*\.php)$ $1 last;
                rewrite ^(.+)$ /index.php?q=$1 last;
            }
            root   /wwwroot/wordpress/;
            index  index.html index.htm index.php;
        }

        location ~ \.php$ {
            root           /wwwroot/wordpress/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
        }
}

目录安全配置 restrictions.conf


location = /favicon.ico {
	log_not_found off;
	access_log off;
}

location = /robots.txt {
	allow all;
	log_not_found off;
	access_log off;
}

# 禁止访问所有的隐藏文件例如 .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
	deny all;
}

# 禁止访问uploads目录中的任何php文件
location ~ ^/wp-content/uploads/.*\.php$ {
	deny all;
}

location ~* /(?:uploads|files)/.*\.php$ {
	deny all;
}

Similar Posts

Content
TOP