nginx自动跳转网页(proxy_pass)

proxy_pass:域名不变

10.10.8.150 --》nginx虚拟主机,在虚拟主机配置文件中添加配置如下

server {

        listen       80;
        server_name www.demo.com;

if ($http_user_agent ~* "Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|MSNBot|ia_archiver|Tomato Bot|FeedDemon|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|YisouSpider|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms") { 
return 403;                ##防盗链
}
location / {
proxy_pass http://10.10.8.151:8090;                               ##要跳转的ip
proxy_redirect off;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 128k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 256k;
                }

}


rewrite:域名也跳转

10.10.8.150 --》nginx虚拟主机,在虚拟主机配置文件中添加配置如下

server {

        listen       80;
        server_name www.demo.com;

rewrite ^(.*)$  http://www.d.com$1 permanent;

}

你可能感兴趣的:(nginx)