hooyes

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

|2017-09-15

请尊重原创,本文原文地址:https://hooyes.net/p/wordpress-nginx-rewrite

描述

这是一个关于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;
}
$ welcome to hooyes.net
[INFO] ------------------------------o-
[INFO] Author : HOOYES
[INFO] Site : https://hooyes.net
[INFO] Page : https://hooyes.net/p/wordpress-nginx-rewrite
[INFO] Last build : 2023-07-31 09:16:20 +0000
[INFO] -0------------------------------
原文地址:https://hooyes.net/p/wordpress-nginx-rewrite
原文地址:https://hooyes.net/p/wordpress-nginx-rewrite

上一篇 冒泡法排序

Content
...
TOP