一、准备nginx安装包(导入或yum安装)
yum 安装最新版nginx:https://www.cnblogs.com/xxoome/p/7256214.html
nginx下载地址:https://nginx.org/download/
安装gcc、pcre-devel、zlib-devel、openssl-devel。
安装指令:
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
下载“nginx-1.9.9.tar.gz”,移动到/usr/local/下。
## 解压
tar -zxvf nginx-1.9.9.tar.gz
##进入nginx目录cd nginx-1.9.9
## 配置./configure --prefix=/usr/local/nginx
# make
make
make install
检测是否安装成功:
# cd到刚才配置的安装目录/usr/loca/nginx/
./sbin/nginx -t
启动nginx
./sbin/nginx
停止/重启nginx
./nginx -s stop ,.nginx -s reload
二、配置转发代理,解决跨域问题
1.proxy_pass后边跟斜杠的问题
假设我们的请求是:http://localhost:8080/api/test.html;而我们要代理的地址是http://192.168.1.1:8888/test.html;
location /api/{
proxy_pass http://192.168.1.1:8888/; --> http://192.168.1.1:8080/test.html
proxy_pass http://192.168.1.1:8888; --> http://192.168.1.1:8080/api/test.html
proxy_pass http://192.168.1.1:8888/hello/; --> http://192.168.1.1:8080/hello/api/test.html
proxy_pass http://192.168.1.1:8888/hello; --> http://192.168.1.1:8080/hellotest.html
}
网友评论