【问题标题】:Wordpress permalinks unauthorized error in nginxWordpress 永久链接 nginx 中的未授权错误
【发布时间】:2019-11-25 06:07:24
【问题描述】:

所以我正在尝试在 LEMP 上运行 wordpress。我确实通过添加这个来修复永久链接

location / {
        try_files $uri $uri/ /index.php?$args;
}

但现在我遇到了未经授权的错误。 更具体地说 -

A password is required to access this web server. Please try again. 

我的虚拟服务器的配置文件

server {
    server_name test.com www.test.com;
    listen x.x.x.x;
    listen 80;
    #return 301 https://$host$request_uri;

}


server {
    server_name test.com www.test.com;
    listen x.x.x.x;
    root /home/test/public_html;
    index index.php;

    access_log /var/log/virtualmin/test.com_access_log;
    error_log /var/log/virtualmin/test.com_error_log;
    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE nginx;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;
    fastcgi_param SCRIPT_FILENAME /home/test/public_html$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param DOCUMENT_ROOT /home/test/public_html;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param REMOTE_PORT $remote_port;
    fastcgi_param SERVER_ADDR $server_addr;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;
    fastcgi_param HTTPS $https;

    access_log /var/log/nginx/test.com.access.log;
    error_log /var/log/nginx/test.com.error.log;




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

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

    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~ /\. {
        deny all;
    }

    # Deny access to any files with a .php extension in the uploads directory
    # Works in sub-directory installs and also in multisite network
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
    }


    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/php-nginx/156327396130368.sock/socket;
    }

    location / {

        auth_basic off;
        try_files $uri $uri/ /index.php?$args;

    }


    listen x.x.x.x:443 ssl;
    ssl_certificate /home/test/ssl.cert;
    ssl_certificate_key /home/test/ssl.key;
    fastcgi_read_timeout 60;
}

PS :- 我正在使用虚拟分钟的预览站点功能

我尝试将 auth_basic off 添加到默认设置以及每个站点配置。它只是行不通

【问题讨论】:

    标签: wordpress nginx webmin virtualmin


    【解决方案1】:

    我们需要保护的目录

    wp-includes 目录将始终如此命名。上传、主题和插件的目录默认是 wp-content 中的子文件夹(分别为 media、wp-content/themes 和 wp-content/plugins),但可以移动到其他地方。 wp-content 目录本身也是如此。

    哦,本页示例中的 access_log 和 log_not_found 语句只是为了不让我们的日志充满垃圾请求。如果要记录请求,请相应地删除语句。

    阻止包含目录中的 PHP 文件

    此位置应始终相同。

    location ~* /wp-includes/.*.php$ {
        deny all;
        access_log off;
        log_not_found off;
        }
    

    阻止内容目录中的 PHP 文件

    此目录默认为 /wp-content,但您可以轻松地将其定义为其他位置,例如只需设置 WP_CONTENT_DIR/WP_CONTENT_URL 常量,因此相应地调整配置。

    location ~* /wp-content/.*.php$ {
        deny all;
        access_log off;
        log_not_found off;
        }
    

    阻止上传目录中的 PHP 文件

    uploads 目录可能是也可能不是 wp-content 的子目录,并且可能已重命名为完全不同的名称,也可能未重命名。相应地调整配置。

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

    文件部分用于默认的多站点/网络路径。如果您愿意,可以将其移除,但留在其中不会造成任何伤害。

    插件和主题目录

    我认为大多数人将主题和插件目录保留为内容目录中的子目录,但它们也可以轻松移动到其他地方。您为插件定义常量对 WP_PLUGIN_DIR/WP_PLUGIN_URL,并为主题使用函数 register_theme_directory() 来执行此操作。如果您也将插件和主题移出内容目录,请为它们添加类似的位置块。

    如果您没有篡改插件或主题位置,请跳过此部分。

    如果您将插件目录移动到例如/模块:

    location ~* /modules/.*.php$ {
        deny all;
        access_log off;
        log_not_found off;
    }
    

    如果您将主题目录移动到例如/皮肤:

    location ~* /skins/.*.php$ {
        deny all;
        access_log off;
        log_not_found off;
    }
    

    如果您同时使用两者,您应该能够像我们使用上面的上传文件夹一样将它们组合起来。

    阻止对 xmlrpc.php 的访问

    如果您不需要 XML-RPC(很可能不需要 - 只有在使用 Jetpack 或 WordPress 手机应用程序时才需要),您可以阻止对它的请求。尽管有些人声称 XML-RPC 不是使用它进行众所周知的攻击的罪魁祸首(尤其是参与使用 XML-RPC 的服务的人),但毫无疑问,您根本无法通过 XML-RPC 受到攻击如果你完全阻止它。所有 XML-RPC 请求都通过 xmlrpc.php 文件进行路由:

    location = /xmlrpc.php {
        deny all;
        access_log off;
        log_not_found off;
    }
    

    您现在减少了应用程序的公共表面,类似于在枪战中侧身站立:攻击者可以攻击的易受攻击的表面现在要小得多。

    【讨论】:

      猜你喜欢
      • 2020-08-04
      • 2013-03-26
      • 2015-02-20
      • 1970-01-01
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 2017-12-07
      • 2017-04-06
      相关资源
      最近更新 更多