wordpress - nginx wordpress wp-admin 重定向到主页

标签 wordpress nginx

在我的 nginx 服务器上,当我访问 example.com/wp-admin 或 example.com/login 时,我总是看到我网站的主页,但是当我访问 example.com/wp-login.php 时,一切正常(并且显示登录屏幕)。

在 nginx 中是否有一些配置可以使这些 url(/wp-admin 或 wp-login)再次工作?

注意:其他帖子的永久链接(例如 example.com/hello-world)正在运行。

我的配置文件是:

<强>1。/etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

<强>2。/etc/nginx/sites-available/worpdress.conf

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/example.com/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    #server_name 127.0.0.1;
        server_name example.com www.example.com;

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

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

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

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        #try_files $uri $uri/ =404;
                try_files $uri $uri /index.php?$args;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

    #   # With php7.0-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;

    #   # With php7.0-fpm:
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_intercept_errors on;
        }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}

<强>3。/etc/nginx/snippets/fastcgi-php.conf

# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;

# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

fastcgi_index index.php;
include fastcgi.conf;

最佳答案

您的 try_files 语句中似乎缺少 /。应该是:

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

第二项 ($uri/) 应该导致 URI /wp-admin 被重定向到 /wp-admin/ 并且然后调用文件 /wp-admin/index.php

参见 this document了解更多。

关于wordpress - nginx wordpress wp-admin 重定向到主页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43146815/

相关文章:

mysql - 优化 WordPress 插件 "Better WordPress Recent Comments"中的慢查询

javascript - 如何获取调用表单的按钮

php - 在 Woocommerce 中以编程方式自定义运费

docker - 如何使用NGINX将请求转发到Docker Microservice

nginx - 如何修复此 NGINX 502 Bad Gateway 错误?

json - 插件 WordPress JSON API - 如何获取具有偏移量的类别的帖子?

php - Nginx - Rails 上的 Wordpress 博客加载带有 mime 类型文本/html 的样式和脚本

Django 与 nginx 总是返回错误 404

Nginx,fastcgi PHP Windows,未指定输入文件

nginx - 带有 Nginx 反向代理和解析器的 Jenkins