简体   繁体   English

301 在 Nginx 中重写永久重定向

[英]301 Rewrite Permanent Redirect in Nginx

Hi still learning linux (running ubuntu 10.04 lts) & nginx (running 1.4.1)thanks for any help, I have found examples of what I want to do but they don't spell it out enough for my comfort level..嗨,仍在学习 linux(运行 ubuntu 10.04 lts)和 nginx(运行 1.4.1)感谢您的帮助,我已经找到了我想做的事情的示例,但它们并没有说明我的舒适度。

I moved site1.com and all it's contents to site2.com and need a permanent 301 redirect as I have many links on other websites I cannot change.我将 site1.com 及其所有内容移动到了 site2.com,并且需要永久 301 重定向,因为我在其他网站上有许多链接,我无法更改。

The best tutorial I have found has told me to do something like this:我找到的最好的教程告诉我做这样的事情:

### redirect beta.cyberciti.biz$URI to www.cyberciti.biz$URI with 301 ###
server {
    listen      75.126.153.206:80;
    server_name beta.cyberciti.biz;
    root        /usr/local/nginx/html;
    index       index.html;
    rewrite     ^ $scheme://www.cyberciti.biz$request_uri permanent;
    # ....
}

however I am confused as to whether I add this whole block changing the variables or if I am supposed to change a server { .... } block that is already in my conf file.但是我很困惑我是否添加了整个块来更改变量,或者我是否应该更改已经在我的 conf 文件中的 server { .... } 块。 I have two server { ... } in my conf file but they are both commented out (see below).. not sure why they are there if they are commented out..我的 conf 文件中有两个 server { ... } 但它们都被注释掉了(见下文).. 如果它们被注释掉,不知道为什么它们在那里..

#     server {
#         listen     localhost:110;
#         protocol   pop3;
#         proxy      on;
#     }
#
#     server {
#         listen     localhost:143;
#         protocol   imap;
#         proxy      on;
#     }

Current nginx.conf is:当前的 nginx.conf 是:

user www-data;
worker_processes  3;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
worker_connections  1024;
# multi_accept on;
}

http {
include       /etc/nginx/mime.types;

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

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;
tcp_nodelay        on;

gzip  on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

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



# mail {
#     # See sample authentication script at:
#     # http://wiki.nginx.org/NginxImapAuthenticateWithApachePhpScript
# 
#     # auth_http localhost/auth.php;
#     # pop3_capabilities "TOP" "USER";
#     # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#     server {
#         listen     localhost:110;
#         protocol   pop3;
#         proxy      on;
#     }
# 
#     server {
#         listen     localhost:143;
#         protocol   imap;
#         proxy      on;
#     }
# }

I inserted what you told me below the http{} block and above all the commented blocks.我在 http{} 块下方和所有注释块上方插入了您告诉我的内容。

In nginx change server_name from site1 to site2 and then create a new site1 block在 nginx 中将server_name从 site1 更改为 site2,然后创建一个新的 site1 块

server {
    listen 80;
    server_name site1.com;
    location / {
        return 301 $scheme://site2.com$request_uri;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM