修改conf文件夹中的nginx.conf文件。
配置代理路径(注意斜杠)
server{
listen 8080;
server_name 192.168.2.5;
location /api {
proxy_pass http://192.168.2.5:8888;
}
}
请求url:http://192.168.2.5:8080/api/getuser
代理路径:http://192.168.2.5:8888/api/getuser
server{
listen 8080;
server_name 192.168.2.5;
location /api {
proxy_pass 192.168.2.5:8888/;
}
}
请求url:http://192.168.2.5:8080/api/getuser
代理路径:http://192.168.2.5:8888//getuser
server{
listen 8080;
server_name 192.168.2.5
location /api/ {
proxy_pass http://192.168.2.5:8888;
}
}
请求url:http://192.168.2.5:8080/api/getuser
代理路径:http://192.168.2.5:8888/api/getuser
server{
listen 8080;
server_name 192.168.2.5;
location /api/ {
proxy_pass http://192.168.2.5:8888/;
}
}
请求url:http://192.168.2.5:8080/api/getuser
代理路径:http://192.168.2.5:8888/getuser
部署多个项目
server {
listen 8080;
server_name name1;
location / {
root html/item1;
index index.html index.htm;
}
}
server {
listen 8080;
server_name name2; /域名2
location / {
root html/item2;
index index.html index.htm;
}
}
不同端口,对应不同项目
server {
listen 8081;
location / {
root html/item1;
index index.html;
}
}
server {
listen 8082;
location / {
root html/item2;
index index.html;
}
}
server {
listen 8083;
location / {
root html/item3;
index index.html;
}
}
相同端口不同路径,对应不同项目,注意第二个location中root为alias 。
server {
listen 8080;
server_name localhost;
location / {
root html/item1;
index index.html index.htm;
}
location /item2 {
alias html/item2;
index index.html index.htm;
}
|