参数用nginx进行反向代理,我这边的有好几个系统,都是不同的IP和端口。我希望在外部访问的时候,是同一个IP和端口。这样可以解决跨域的问题,

结构图:

通过每个系统的网址可以直接访问,另外,我们通过Nginx的IP地址也可以直接访问。

其实主要是在配置文件里面修改:

增加代理的配置


#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;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location  / {if ( $request_uri ~ "^\/onePage" ){proxy_pass   http://127.0.0.1:8080;}if ( $http_referer ~ "^http://127.0.0.1/onePage"){proxy_pass   http://127.0.0.1:8080;}if ( $request_uri ~ "^\/twoPage" ){proxy_pass   http://127.0.0.1:8081;}if ( $http_referer ~ "^http://127.0.0.1/twoPage"){proxy_pass   http://127.0.0.1:8081;}}#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;#    }#}}

主要是修改location这里的配置设置

request_uri 是浏览器的请求的url,通过匹配进行跳转

        if ( $request_uri ~ "^\/onePage" ){proxy_pass   http://127.0.0.1:8080;}

后来发现一个问题,就是跳转之后的js,css无法获取到,这里我们还需要增加一个过滤

由于发现http_referer可以区分出不同的系统,所以用其来来把css js 这些进行重新路由。

        if ( $http_referer ~ "^http://127.0.0.1/onePage"){proxy_pass   http://127.0.0.1:8080;}

第二个系统也用同样的配置方式。

nginx之反向代理配置相关推荐

  1. nginx搭建反向代理配置并测试

    前言: 如今信息时代,对于web服务器的要求很高,既要性能,又要稳定性,又经济最好免费,还要满足公司的各大奇葩业务需求,越来越挑剔,就像你去买手机,中意的是外观好看,功能强大,拍照清晰,存储大,不死机 ...

  2. nginx反向代理模块配置详解_nginx反向代理配置详解

    反向代理配置 修改部署目录下conf子目录的nginx.conf文件(如/opt/nginx/conf/nginx.conf)内容,可调整相关配置. 将默认配置里面带#号注释内容去掉 grep -v ...

  3. 反向代理配置:location 后面的规则带斜杆和不带斜杆的区别

    1.在nginx中配置proxy_pass代理转发时: 如果在proxy_pass后面的url加/,表示绝对根路径: 如果没有/,表示相对路径,把匹配的路径部分也给代理走. 在 Nginx 的反向代理 ...

  4. 【网络编程】多个服务器的情况:nginx实现反向代理、nginx基于反向代理实现负载均衡

    如果我们有多个服务器,比如我们只有一个域名:我们可以利用其中一台服务器,通过nginx为这一个域名实现反向代理:进一步,我们可以利用这多台服务器,为这一个域名基于nginx的反向代理实现负载均衡. 文 ...

  5. Nginx http和反向代理配置实例介绍

    Nginx  是一个高性能的 HTTP 和反向代理服务器,本节以实际实例介绍如何实现Nginx 反向代理. 1.  安装Nginx 安装Nginx之前,首先安装相关模块的依赖库: 这里安装Pcre和O ...

  6. Nginx教程系列四:实现反向代理配置

    文章目录 案例一 安装tomcat 配置Nginx反向代理 测试 案例二 安装第二个tomcat实例 准备测试页面 配置Nginx反向代理 测试 location 指令说明 案例一 预先安装nginx ...

  7. nginx反向代理配置及优化

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://liuyu.blog.51cto.com/183345/166381 nginx反 ...

  8. ci框架 反向代理配置_《网站建设》Nginx配置反向代理

    [网站克隆] nginx反向代理镜像站点做贼站谈Nginx,实力是反向代理,因为研究肉鸡刷Adsense使用,花了1-2天来弥补Nginx的知识,发现有搜索. [网站克隆] nginx反向代理镜像站点 ...

  9. nginx反向代理配置实例分享

    nginx反向代理配置一例. 配置内容如下: user www www; worker_processes 8; error_log /usr/local/webserver/nginx/logs/n ...

最新文章

  1. jquery ajax 序列化表单传参提交实体对象到后台action
  2. C语言实现割线法求零点以及详解割线法
  3. 鸟哥的Linux私房菜(基础篇)-第五章、首次登陆与在线求助 man page
  4. c语言栈解决迷宫问题,栈处理迷宫问题
  5. 电脑音响怎么插_厦门靓车港丰田凯美瑞汽车音响改装德国HELIX汽车音响|凯美瑞|音响改装|汽车|内饰...
  6. 配置文件中的数据库连接串加密了,你以为我就挖不出来吗?
  7. ElasticSearch-Hadoop:从Hadoop到ElasticSearch索引产品视图计数和客户顶部搜索查询
  8. 让IE支持HTML5
  9. 原根(扩展欧几里得+欧拉函数)
  10. Oracle 数据块 Block 说明
  11. 【Spark】Spark 3.0 支持 event logs 滚动
  12. 如何开始一个深度学习项目
  13. 使用select模型详细介绍并使用此模型来监视标准输入缓冲区stdin里是否还有数据
  14. 多项目同时进行 如何高效协作?
  15. java基础app开发教程_安卓app开发基础入门
  16. Unity3D隐藏启动logo
  17. 大数据hadoop学习【9】-----通过JAVA语言编程,实现对Hbase数据库表及数据的相关操作
  18. 京东智联云贪心科技:图卷积神经网络在推荐系统的应用
  19. PM应具备的规划技巧-顾客价值管理
  20. ceph集群全部停机开机

热门文章

  1. 集群tomcat+session共享
  2. JavaScript学习笔记 1
  3. IIS 500 错误解决
  4. myeclipse中svn图标状态(同步标记)不显示问题的解决方法
  5. 关于C#_ArrayList的两篇文章
  6. 移动开发 Jetpack Compose 组件布局
  7. Pytext简介:facebook的基于PyTorch的NLP框架
  8. Epic Citadel Demo展示互联网作为游戏平台的巨大能量
  9. Mybatis常见面试题总结和基本概念
  10. Spring框架(IoC、AOP面向接口切面)