nginx做域名轉發和uri轉發


一、 域名轉發 www.qq.com ------> www.baidu.com  

  nginx部署在192.168.1.100,本地配置host 192.168.1.100 www.qq.com ,瀏覽器輸入www.qq.com會跳轉到www.baidu.com

 

# vi  /etc/nginx/nginx.conf

user nginx;
worker_processes 1;

events {
use epoll;
worker_connections 10240;
}

http {

server {
listen 80;
server_name www.qq.com;
rewrite ^/(.*)$ http://www.baidu.com/$1 last;
}
}

 

 

二、 同一個域名內URI轉發  www.qq.com/xxx ------> www.qq.com/main/xxx

  根目錄設置為/data/gg,將所有對根目錄的請求都轉發到根目錄下的main目錄,請求帶過來的參數不變

#vi /etc/nginx/nginx.conf
user nginx;
worker_processes 1;

events {
use epoll;
worker_connections 10240;
}

http {

server {
listen 80;
server_name localhost;
location / {
root /data/gg;
}
rewrite ^/([a-z0-9]+)$ /main/$1 last;
}
}

 

 

附nginx操作命令:

nginx version: nginx/1.5.7
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /etc/nginx//)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file

 

三、 nginx轉發代理配置

location ^~ /idata/ {
proxy_pass http://www.idata.com/;
proxy_pass_header Server;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM