加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

将root重定向到nginx下的WordPress子文件夹

发布时间:2020-12-14 02:26:57 所属栏目:Linux 来源:网络整理
导读:我最近得到了一个带有nginx的VPS并且移动了我的WordPress实例.经过一番浏览后,我得到了永久性的工作.该博客位于博客文件夹中. 我想将example.com的请求重定向到example.com/blog.但是,请求toexample.com/doc / …不应重定向到example.com/blog/doc / …. 我
我最近得到了一个带有nginx的VPS并且移动了我的WordPress实例.经过一番浏览后,我得到了永久性的工作.该博客位于博客文件夹中.

我想将example.com的请求重定向到example.com/blog.但是,请求toexample.com/doc / …不应重定向到example.com/blog/doc / ….

我已经寻找其他问题/答案,但它们都导致了无限重定向循环.

这是当前的配置:

server {
    listen 80;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /usr/share/nginx/html;

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

    server_name mysite.com;

    location / {
            # Redirect to /blog
    }

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

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

    # pass the PHP scripts to FastCGI server listening on the php-fpm socket
    location ~ .php${
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

    }
}

“`

解决方法

用这个:
location = / {
    return 301 http://example.com/blog;
}

这里的关键是=,这使得nginx仅将此规则应用于到达根文件夹的请求,而不是其他地方.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读