子文件夹中的WordPress安装不能与nginx一起使用

时间:2017-11-30 作者:Ivan Slaughter

在nginx服务器中,场景是在子文件夹mydomain中安装Wordpress。com/new,具有特定于域的nginx配置(conf.d/mydomain.com.conf),如下所示:

server  {
listen 80;
server_name mydomain.com *.mydomain.com;
root    /var/www/mydomain;
index   index.php index.html index.htm;
# error_log  /var/log/nginx/mydomain-error.log warn;

aio threads;
    set_real_ip_from 127.0.0.1;
    set_real_ip_from 10.0.0.0/8;
    real_ip_header X-Real-IP;
    add_header      Via     "1.1 varnish-v4.1";
    gzip_vary       off; # already handled from upstream server

    include includes/cloudflare.conf;
    include includes/fastcgi-wordpress.conf;

location / {
    try_files $uri $uri/ /index.php?$args /index.php?q=$uri&$args;
    expires 30d;
}

    # Deny access to uploads that aren’t images, videos, music, etc.
    location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php|js|swf)$ {
        deny all;
    }

    # Deny public access to wp-config.php
    location ~* wp-config.php {
        deny all;
    }

    # Deny access to wp-login.php. Do not enable due to admin-ajax.php!! T_T
    # location = /(wp-login|login).php {
    #    limit_req zone=one burst=1 nodelay;
    #    fastcgi_pass 127.0.0.1:9000;
    # }

    location ~ \\.php$ {
            try_files $uri /index.php;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            include includes/fastcgi-http.conf;
    }

# location ~ /purge(/.*) {
#     fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
# }  

location ~* ^.+\\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|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 = /robots.txt {
    access_log off;
    log_not_found off;
}

location ~ /\\. {
    deny  all; 
    access_log off;
    log_not_found off;
}

}
mydomain。com运行正常,但在mydomain中。com/new |所有媒体和永久链接保持重定向到mydomain。com而不是mydomain。com/新。应该修改哪个配置来修复此问题?我对这个nginx配置不熟悉,如果配置失败,如何防止整个服务器/域出错(此服务器中有多个域),非常感谢您的帮助。

1 个回复
SO网友:Ivan Slaughter

问题解决了,我只需要添加一个位置条目,如下所示:

location /new {
    try_files $uri $uri/ /new/index.php?$args /new/index.php?q=$uri&$args;
}

结束

相关推荐

Nginx-与URL中的.php进行的固定链接不起作用

我正在将一个站点从Apache服务器移动到nginx服务器。很多页面都有一个。permalink末尾的php扩展。尝试查看这些页面会导致找不到nginx 404。然而,这些页面在Apache上运行良好。以下是站点的服务器块配置:# Vhost Config: example.com server { root /var/www/vhosts/sites/www.example.com/web; index index.php index.html ind