标签:lnmp
server {
listen 80;
server_name aaa.com;
location / {
proxy_pass http://2.2.2.2/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# access_log /home/logs/aaa_access.log combined;
}
如果后端的机器有多台
upstream bbb
{
server 1.2.3.1:80;
server 1.2.3.4:80;
}
server {
listen 80;
server_name bbb.com;
location / {
proxy_pass http://bbb/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# access_log /home/logs/bb_access.log combined;
}
代理一个服务器上所有域名
在vhosts目录下
Vi servername
server_name www.123.net.cn www.alsdjfl.com www.asdfa1.com; //就这么简单一行,当然这个server_name 还可以继续添加的
(2) 虚拟主机配置文件
server {
listen 80;
include vhosts/servername; // 这里的文件就是上边那个servername列表文件
location / {
proxy_pass http://1.2.1.2/; //这里就是需要做代理的服务器ip地址了
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
access_log /dev/null;
}
根据访问的目录来区分后端的web
upstream aaa.com
{
server 192.168.111.6;
}
upstream bbb.com
{
server 192.168.111.20;
}
server {
listen 80;
server_name li.com;
location /aaa/
{
proxy_pass http://aaa.com/aaa/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /bbb/
{
proxy_pass http://bbb.com/bbb/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /
{
proxy_pass http://bbb.com/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
proxy_pass http://aaa.com/aaa/ 这里必须要加这个目录,不然就访问到根目录了。
本文出自 “IT屌丝” 博客,请务必保留此出处http://68686789.blog.51cto.com/10438688/1832180
标签:lnmp
原文地址:http://68686789.blog.51cto.com/10438688/1832180