使用 Nginx 在子目录中使用 WordPress

使用 Nginx 在子目录中使用 WordPress

无论我做什么,我的 WordPress 网站都运行良好,包括所有永久链接,但我无法访问 wp-admin 区域。每当我尝试这样做时,我都会收到 404 错误。我已将 WordPress 安装在其自己的目录中,简称为“wordpress”。这是我的配置文件:

    server {
    listen 443 ssl;
    server_name my-domain.com;
    root /home/wp-user/my-domain.com/public;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    index index.html index.htm index.php;

    charset utf-8;

    # 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;
    }

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

    access_log off;
    error_log  /var/log/nginx/my-domain.com-error.log error;

    # 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;
    }

    # WordPress single blog rules.
    # Designed to be included in any server {} block.

    # This order might seem weird - this is attempted to match last if rules below fail.
    # http://wiki.nginx.org/HttpCoreModule
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }


    # Directives to send expires headers and turn off 404 error logging.
    location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        access_log off; log_not_found off; expires max;
    }

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

    location ~ \.php$ {
        try_files $uri /wordpress/index.php;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone:
        #fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        proxy_intercept_errors on;
        error_page 502 = @fallback;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root;
        include fastcgi_params;
    }

    location @fallback  {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

答案1

wp-admin 是与 index.php 不同的页面,因此您的位置指令永远不会访问它。您基本上将您的位置设置为 /WordPress 并将您的 .php 位置嵌套在其中。我使用的是平板电脑,因此当我再次使用台式机/笔记本电脑时,我会添加一个示例代码片段。

相关内容