listen指定的就是站點端口室叉,可以在不沖突的前提下自定義配置玖绿,server_name指定域名基括、index 指定默認(rèn)首頁期犬、root指定根目錄
本地設(shè)置域名映射除了serve_name之外河哑,還要設(shè)置hosts
sudo vim /etc/hosts
127.0.0.1 www.baidu.com
1,反向代理
http://www.ttlsa.com/nginx/use-nginx-proxy/
server{
listen [你要監(jiān)聽的端口號];
server_name [你要監(jiān)聽的域名/IP];
location / {
proxy_pass [代理的目標(biāo)地址];
}
}
server{
? ? ? listen 80; ? #監(jiān)聽80端口
? ? ? server_name ?xxx.com; ? #域名
? ? ? location / {
? ? ? proxy_pass http://ip:端口/; ? #實際ip ?端口
? ? ? proxy_redirect off;
? ? ? proxy_set_header X-Real-IP $remote_addr;
? ? ? proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
? ? ?}
}
2龟虎,配置虛擬主機
server{
? ? ?listen 端口 default; ? ?
? ? server_name _*; ? #可以用域名
? ? access_log? logs/www.xx.com.access.log? main;? #設(shè)定本虛擬主機的訪問日志
? ?location / {
? ? ? ? ? ? ?root ? /root;? ? ? #定義服務(wù)器的默認(rèn)網(wǎng)站根目錄位置
? ? ? ? ? ? ?index index.html;? #定義首頁索引文件的名稱
? ? ?}
}
反向代理
admin.funliving.com/api/v1? ——>http://139.224.69.217:9000/
server{
listen? ? ? 80;
server_name admin.funliving.com;
root? /home/www/funliving-admin;
allow all;
location ^~ /api/v1/ {
proxy_pass http://139.224.69.217:9000/;
}
location / {
index? index.html;
try_files $uri $uri/ /index.html;
}
}