nginx 报出301 Moved Permanently原因
时间: 2024-01-10 12:21:51 浏览: 29
根据提供的引用内容,Nginx报出301 Moved Permanently的原因是进行了永久重定向。这意味着服务器已经将请求的资源永久移动到了新的位置,并且将来的请求应该直接访问新的URL。这种重定向通常用于将旧的URL重定向到新的URL,以便保持搜索引擎排名和用户书签的一致性。
Nginx中配置301重定向的方法如下:
```nginx
server {
listen 80;
server_name nowamagic.net;
return 301 http://www.nowamagic.net$request_uri;
}
server {
listen 80;
server_name www.nowamagic.net;
return 301 http://nowamagic.net$request_uri;
}
```
上述配置将nowamagic.net重定向到www.nowamagic.net,同时将www.nowamagic.net重定向到nowamagic.net。
相关问题
nginx 301 Moved Permanently
Nginx使用301 Moved Permanently状态码来进行永久重定向。当用户输入一个不存在的地址时,Nginx会根据用户的配置来决定是否进行页面重定向以及如何进行重定向。如果用户输入的地址最后部分是一个文件目录,且Nginx在运行过程中没有找到该文件但发现目录存在,则会设置301 Moved Permanently状态码进行重定向。这意味着用户的请求将被永久重定向到目录所对应的URL地址。 <span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [深度硬核文:Nginx的301重定向处理过程分析](https://blog.csdn.net/u010046887/article/details/114092486)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
nginx 配置中如何阻止301 Moved Permanently
根据提供的引用内容,我们可以得出以下结论:nginx会自动进行301跳转,但是如果我们不想进行301跳转,可以在配置文件中添加以下代码:
```nginx
if ($request_uri = /old-url) {
return 200 'This is the old content';
}
```
其中,/old-url是需要阻止301跳转的URL,'This is the old content'是需要返回的内容。这样,当用户访问/old-url时,就会返回'This is the old content',而不会进行301跳转。