使用Nginx的SubDirectory中的WordPress

无论我做什么,我的WordPress网站的工作很好,包括所有永久链接,但我无法访问wp-admin区域。 每当我尝试这样做,我得到一个404错误。 我已经将WordPress安装到自己的目录中,简称为“WordPress”。 这是我的configuration文件:

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

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