我最近得到了一个带有nginx的VPS,并将我的WordPress实例移走了。 经过一番浏览,我得到了固定链接工作。 博客位于blog文件夹内。
我想请求example.comredirect到example.com/blog 。 但是,对example.com/doc/...请求不应该redirect到example.com/blog/doc/...
我寻找其他问题/答案,但他们都导致了无限的redirect循环。
这是目前的configuration:
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只将这个规则应用于到达根文件夹的请求,无处不在。