一、下载
http://nginx.org/en/download.html
二、安装启动
2.1 解压进入目录
2.2 启动
start nginx
2.3 查看任务进程
tasklist /fi "imagename eq nginx.exe"
三、配置
3.1 目录下新建vhost文件夹
3.2 新建扩展配置文件 api.conf
server {
listen 9000;
server_name 172.16.2.180;
charset utf-8;
# 前端匹配
location / {
# 跨域配置
add_header Cache-Control "no-cache, no-store";
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "*";
add_header Access-Control-Allow-Headers "*";
root html;
index index.html index.htm;
}
# 后端匹配
location /api/ {
proxy_pass http://127.0.0.1:8099/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
3.3 配置conf引入扩展配置文件
include e:/tools/nginx-1.20.1/conf/vhost/*.conf;
四、重启
4.1 查看配置正确性
nginx -t
4.2 重新加载
nginx -s reload
|