安装与部署:
以路劲的方式来区分项目:
nginx.conf的配置文件
配置说明:
1、listen:端口号
2、server_name:虚拟ip地址
3、root:声明默认网站根目录位置 --项目的根目录
4、index:定义首页索引文件的名称 --index.html
5、try_files:定义查找文件规则,找到指定默认文件
6、location:控制服务访问路径
7、proxy_pass:请求代理转发
8、alias:与root指令一样,用于指定项目文件路径;区别是alias是目录别名,root是最上层目录的定义,对URI的处理方式各有不同
server {
listen 8011;
server_name 192.168.1.6;
#控制服务访问路径
location / {#192.168.1.6:8011(A项目)
#找的是nginx目录html/pc路径下的index.html访问页面
root html/pc;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /app{#192.168.1.6:8011/app(B项目)
#找的是服务器上/data/nginx/html/app目录下的index.html访问页面
alias /data/nginx/html/app;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /api/ {#192.168.1.6:8011/api/(C项目)注:后端服务
#这里设置是通过访问 192.168.1.6:8011/api/ 代理转发到 192.168.1.6:8010 服务
proxy_pass http://192.168.1.6:8010; #代理转发
}
#指定错误代码, 统一定义错误页, 错误代码重定向到新的Locaiton(默认就有)
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}