WordPress Nginx 安全配置 – 禁用某些目录执行PHP

以下我们将介绍Wordpress Nginx 安全配置:禁用某些目录执行PHP,详细说明查看如下配置信息:

server {
        listen 80;
        server_name website.com;
    # Redirect non-www to www (website.com -> www.website.com)
        return 301 http://www.$server_name$request_uri;
}
 
server {
        listen 80;
        server_name www.website.com;
        access_log /var/www/website.com/logs/access.log main;
        error_log /var/www/website.com/logs/error.log warn;
    root /var/www/website.com/public/htdocs;
    index index.html index.htm index.php;
 
    # 日志不记录 robots.txt
        location = /robots.txt {
            log_not_found off;
            access_log off;
        }
 
        # 如果没有 favicon 文件则退出并返回 204 (没有错误内容)
        location ~* /favicon.ico$ {
            try_files $uri =204;
            expires max;
            log_not_found off;
            access_log off;
        }
 
        # 以下格式文件日志不需要记录
        location ~* .(js|css|png|jpg|jpeg|bmp|gif|ico)$ {
            expires max;
            log_not_found off;
        access_log off;
        # Send the all shebang in one fell swoop
        tcp_nodelay off;
        # Set the OS file cache
        open_file_cache max=1000 inactive=120s;
        open_file_cache_valid 45s;
        open_file_cache_min_uses 2;
        open_file_cache_errors off;
        }
 
        # http://wiki.nginx.org/WordPress
        # 设置静态地址必须要添加的配置
        # 如果你后台添加了固定链接,则需要添加以下配置
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
 
    # 禁止访问 htaccess 文件
        location ~ /. {
            deny  all;
        }
 
        # 禁止访问 /wp-content/ 目录的 php 格式文件 (包含子目录)
        location ~* ^/wp-content/.*.(php|phps)$ {
            deny all;
        }
 
        # 允许内部分  wp-includes 目录的 .php 文件 
        location ~* ^/wp-includes/.*.(php|phps)$ {
            internal;
        }
 
    # 禁止访问 wp-config.php 文件
        location = /wp-config.php {
            deny all;
        }
 
        # 禁止访问 /wp-content/ 目录的以下文件格式 (包含子目录)
        location ~* ^/wp-content/.*.(txt|md|exe)$ {
            deny all;
        }
 
    # 处理 .php 文件
        location ~ .php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+.php)(/.+)$;
            include /etc/nginx/fastcgi_params;
            fastcgi_connect_timeout 180s;
            fastcgi_send_timeout 180s;
            fastcgi_read_timeout 180s;
            fastcgi_intercept_errors on;
            fastcgi_max_temp_file_size 0;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_index index.php;
        }
 
        # wordpress 重写规则
        rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
        rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
 
        # Add trailing slash to */wp-admin requests
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
}

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
  1. 免费下载或者VIP会员资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
  2. 提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。 若排除这种情况,可在对应资源底部留言,或联络我们。
  3. 找不到素材资源介绍文章里的示例图片?
    对于会员专享、整站源码、程序插件、网站模板、网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
  4. 付款后无法显示下载地址或者无法查看内容?
    如果您已经成功付款但是网站没有弹出成功提示,请联系站长提供付款信息为您处理
  5. 购买该资源后,可以退款吗?
    源码素材属于虚拟商品,具有可复制性,可传播性,一旦授予,不接受任何形式的退款、换货要求。请您在购买获取之前确认好 是您所需要的资源

评论(0)

提示:请文明发言