nginx 反向代理 解决跨域 问题

2019-11-25  本文已影响0人  々柯童鞋々

1、首先 nginx官方网站下载 版本,或者用这个传送门

2、打开ngixn安装目录下/conf/nginx.conf。

3、找到http 模块,新建一个server

server {
        listen       80;
        server_name  abc.test.com;//域名

        autoindex on;
        autoindex_exact_size on;
        autoindex_localtime on;

        location / { //默认是 / 当前目录 也可以 /api/ 二级目录
            #expires 12h;
            #if ($request_uri ~* "(php|jsp|cgi|asp|aspx)")
            #{
            #     expires 0;
            #}
            proxy_pass http://192.168.1.39:8081/;

            #if (!-e $request_filename){
            #   rewrite  ^(.*)$  /index.php?s=$1  last;   break;
            #}
            #持久化连接相关配置
            #proxy_connect_timeout 30s;
            #proxy_read_timeout 86400s;
            #proxy_send_timeout 30s;
            #proxy_http_version 1.1;
            #proxy_set_header Upgrade $http_upgrade;
            #proxy_set_header Connection "upgrade";

            #add_header X-Cache $upstream_cache_status;
        }
}

注:此处展示部分配置,注释的部分看需要打开。

4、 nginx windows电脑启动命令

d: //windows 进度D盘操作
cd nginx //看自己安装的目录
start nginx 启动服务(windows 版本 可以直接 打开nginx 目录下的 nginx.exe启动服务)
nginx -s stop 停止服务
nginx -s reload 重启服务

5、访问 http://abc.test.com/ 或者 http://abc.test.com/api (二级目录)

未完待续...

上一篇下一篇

猜你喜欢

热点阅读