一、 域名转发 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;
}
}