nginx代理配置

2020/07/20 node,nginx

1、查询是否安装nginx

brew search nginx  // 查询要安装的软件是否存在

2、安装nginx

brew install nginx // 运行安装

3、启动nginx

nginx -t // 查看nginx.conf 路径

sudo nginx -c /usr/local/etc/nginx/nginx.conf

avatar

查看是否启动成功

访问 http://localhost:8080/ 看到 Welecome to nginx ——— 以上nginx已配置成功,接下来根据项目添加nginx配置文件即可 ———

4、根据项目配置nginx文件

备注:以下 名称相同

cd /usr/local/etc/nginx/    // 进入nginx目录
mkdir servers && cd servers  // 创建servers文件夹存放配置文件
touch <project-name>.conf //  创建nginx配置文件

配置本地host

在host 中添加 127.0.0.1

例:.conf

server {
    listen 80;
    server_name <project-name>; // 本地项目访问地址
    location  ~ .*\.(json|gif|jpg|png|htm|html|css|js|flv|ico|swf|eot|svg|ttf|woff|pdf)(.*) {
        proxy_buffering off;
        proxy_pass http://demo.api.com:8081; //项目启动需要被代理的地址ps 后端接口的域名
    }
    location /public-common-api/api/ {  //接口/public-common-api/api/ 接口公共请求的路径
        proxy_buffering off;
        proxy_pass http://127.0.0.1:8000; // 项目请求接口的被代理的地址
    }
}

5、重启nginx

sudo nginx -s reload

Search

    Table of Contents