Nginx反向代理以伪装站点登录
来源:互联网 发布:闪电网络测速工具 编辑:程序博客网 时间:2024/06/08 19:50
最近在公司开发一个erp项目,这个项目是公司项目A下的一个子项目。需要登录以获得权限才能进入此erp系统。
例如:项目A主站:www.aaa.com 已经在公司服务器192.168.45.21 上布好了
erp子系统:www.aaa.com/erp/ 需要本机调试,调试时的url为127.0.0.1:8080/erp/
因此在仅调试此erp子项目的时候,由于localhost是不能保存cookie的,就遇到了一个问题,如何在没有项目A主站代码的情况下进入这个erp系统。
解决方法如下:使用nginx反向代理。
同时,在本机hosts文件中添加:127.0.0.1 www.aaa.com 使得本机nginx服务器可以解析www.aaa.com的所有请求。
当请求为主站的时候,直接交给公司服务器192.168.45.21来处理并返回结果;
当请求为erp子系统的时候,就交给本机localhost的调试系统来处理并返回结果。
这样就可以解决登录的权限问题。
整体框图如下:
下面给出nginx的相关配置文件nginx.conf:
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream erpTest {server 127.0.0.1:8080;} upstream testHome {server 192.168.45.21;} server { listen 80; server_name localhost www.aaa.com;proxy_set_header Host $host; #charset koi8-r; access_log logs/host.access.log main; location ^~ /erp/ { proxy_pass http://erpTest; }location / { proxy_pass http://testHome;} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}
阅读全文
0 0
- Nginx反向代理以伪装站点登录
- Nginx反向代理和多站点配置实现及问题解决
- Nginx反向代理Nginx
- Nginx反向代理Nginx
- nginx 反向代理
- nginx 反向代理
- Nginx 反向代理https
- Nginx 反向代理设置
- nginx反向代理
- nginx 反向代理上网
- Nginx 反向代理设置
- NGINX实现反向代理
- nginx TCP 反向代理
- nginx 反向代理
- nginx反向代理配置
- nginx反向代理原理
- nginx反向代理配置
- Nginx反向代理设置
- ArrayList、LinkedList、LinkedHashMap源码分析
- HDU 1796 How many integers can you find【容斥原理】
- Centos5.5 IDT HOOK
- Python交互环境下如何输入代码
- php搭建环境
- Nginx反向代理以伪装站点登录
- OkHttp源码分析
- iOS/Swift3.0 终端命令自动打包
- Maven实践---导航
- Android InputMonitor
- StructuredStreaming官方文档翻译
- TCP/IP协议、socket及socket简单实现网络通讯
- php mysql数据库操作类
- socket之UDP通信