跨域访问方法-Nginx反向代理
2016-06-28 17:37
555 查看
1. nginx安装
(1) 安装pcre下载链接:https://sourceforge.net/projects/pcre/files/latest/download?source=files
下载后解压压缩包,进入解压后文件夹的目录,打开终端。
运行命令:$ sudo ./configure --prefix=/usr/local $ sudo make $ sudo install
(2) 安装nginx
下载链接:
Linux:http://nginx.org/download/nginx-1.10.1.tar.gz
windows:http://nginx.org/download/nginx-1.10.1.zip
下载后解压压缩包,进入解压后文件夹的目录,打开终端。
运行命令:$ sudo ./configure --prefix=/usr/local/nginx --with-cc-opt="-Wno-deprecated-declarations" $ sudo make $ sudo install 配置环境变量: 运行命令: $ touch ~/.bash_profile $ open ~/.bash_profile 编辑bash_profile文件,向PATH新增nginx变量: export PATH=$PATH:/usr/local/nginx/sbin
2. nginx操作
(1) 启动nginx:运行命令:$ nginx 打开浏览器http://localhost,看到以下页面则表明nginx运行正常 Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com.
Thank you for using nginx.
(2) 关闭nginx:
运行命令:$ nginx -s stop
(3) 重启nginx:
运行命令:$ nginx -s reload
3. nginx 反向代理配置
(1) 进入nginx的conf目录:运行命令:$ cd /usr/local/nginx/conf
(2) 修改nginx.conf文件:
运行命令:$ vi nginx.conf 修改如下内容: server { listen 9000; server_name localhost; autoindex off; index index.html index.htm index.php; #charset koi8-r; #access_log logs/host.access.log main; location / { #root html; proxy_pass http://localhost:8080/; index index.html index.htm; } location /BCYS-Market-biz/ { #rewrite ^.+api/?(.*)$ /BCYS-Market-biz/$1 break; proxy_pass http://120.76.97.189:21080; } } 保存后退出
(3) 重启nginx
参考资料:
用nginx的反向代理机制解决前端跨域问题:http://www.w2bc.com/Article/86876
nginx配置location总结及rewrite规则写法:http://seanlook.com/2015/05/17/nginx-location-rewrite/
相关文章推荐
- FastDFS安装与nginx反向代理配置
- 一张图了解正向代理和反向代理
- Nginx反向代理和负载均衡
- Nginx负载均衡与反向代理实现动、静态网页分离实现图
- Nginx反向代理关于端口的问题
- Nginx正反向代理、负载均衡等功能实现配置
- Nginx+Tomcat反向代理,负载均衡。
- Nginx之(正)反向代理
- 反向代理及请求负载均衡Nginx开发搭建
- Nginx反向代理
- 正向代理与反向代理
- Nginx+Apache实现反向代理
- 反向代理
- 正向代理和反向代理的区别
- 正向代理与反向代理
- Nginx+Tomcat实现反向代理
- nginx反向代理cas server之1:多个cas server负载均衡配置以及ssl配置
- Nginx反向代理实现Tomcat多个应用80端口访问
- Nginx负载均衡和反向代理设置
- SSH做反向代理