一、 域名轉發 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;
}