nginx 代理多个服务器——多个server方式
原文链接:https://blog.csdn.net/wild46cat/article/details/52997005
-------------------------------------------------------------
配置文件下载地址:https://download.csdn.net/download/zengmingen/10462400
nginx 代理多个服务器——多个server方式
- #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 9922;
- server_name firstProxyServer;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- #location / {
- #root html;
- #index index.html index.htm;
- #}
- location / {
- proxy_pass http://localhost:8989;
- }
- #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;
- #}
- }
- server {
- listen 9977;
- server_name secondProxyServer;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- #location / {
- #root html;
- #index index.html index.htm;
- #}
- location / {
- proxy_pass http://localhost:8080;
- }
- #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;
- # }
- #}
- }
其中主要的是有两个server,每个server对应的被代理的服务器的不同。从而实现了nginx代理多个服务器的目的。
- server {
- listen 9922;
- server_name firstProxyServer;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- #location / {
- #root html;
- #index index.html index.htm;
- #}
- location / {
- proxy_pass http://localhost:8989;
- }
- #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;
- #}
- }
- server {
- listen 9977;
- server_name secondProxyServer;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- #location / {
- #root html;
- #index index.html index.htm;
- #}
- location / {
- proxy_pass http://localhost:8080;
- }
- #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;
- #}
- }
下面是测试的结果:
nginx 代理多个服务器——多个server方式相关推荐
- 详解nginx 代理多个服务器(多个server方式)
其中主要的是有两个server,每个server对应的被代理的服务器的不同.从而实现了nginx代理多个服务器的目的. user root; worker_processes 1;#error_log ...
- Nginx代理内网服务器访问外网
Nginx代理内网服务器访问外网 1.SpringBoot工程配置文件改写 2. SpringBoot静态工具类注入配置文件变量 3. SpringBoot 使用 4. 配置Nginx 问题描述: 有 ...
- nginx 代理 portainer 报 Unable to retrieve server settings and status
一.nginx配置 location /portainer {proxy_pass http://localhost:19000/;proxy_set_header Via "nginx&q ...
- Nginx:12---反向代理之(代理模块,代理单个上游服务器)
一.反向代理介绍 反向代理应该是 Nginx 做的最多的一件事了,什么是反向代理呢,反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网 ...
- Nginx代理上传文件大小设置
一,安装nginx配置 进入nginx配置文件–>conf–>nginx.conf #user nobody; worker_processes 5; events {worker_con ...
- Nginx代理sftp配置
最近有几个项目组的同事都在咨询nginx代理sftp的问题,那今天就写下此博文以供大家参考.献丑了! 0. 环境 主机名 IP 角色 nginx 192.168.10.182 代理服务器 sftp_s ...
- Nginx配置实例-反向代理实现浏览器请求Nginx跳转到服务器某页面
场景 Ubuntu Server 16.04 LTS上怎样安装下载安装Nginx并启动: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/detai ...
- Nginx——反向代理多个服务器
反向代理单个服务器 在配置反向代理之前,你需要保证你的系统中已经成功安装了Tomcat 配置过tomcat之后,我们可以通过ip+端口号访问tomcat,tomcat默认端口是8080,访问之后会得到 ...
- Nginx快速入门(三)正向代理、HTTP服务器与动静分离
3.HTTP服务器 Nginx本身也是一个静态资源的服务器,当只有静态资源的时候,就可以使用Nginx来做服务器,同时现在也很流行动静分离,就可以通过Nginx来实现,首先看看Nginx做静态资源服务 ...
最新文章
- Handler 实现的一个延时操作
- 异部时钟电路的FPGA设计
- Python语言学习:利用sorted对字典按照value进行递减排序,输出列表,并给定排名索引,组成新字典输出
- 武大上交发布首篇「图像匹配」大领域综述!涵盖 8 个子领域,汇总近 20年经典方法
- 贪心只能过样例 loj515
- ubuntu gedit出错:Failed to connect to the session manager
- React ref的转发
- oracle中 start with,Oracle中connect by...start with...的使用
- Keep-Alive功能使客户端到服务器端的连接持续有效
- Docker下ETCD集群搭建
- Ext.util.Format.date与Ext.Date.format区别, 转换时间戳
- html宠物医院制作与实现,基于JSP的宠物医院系统设计与实现-毕业设计.doc
- HTML设置半透明的背景,CSS设置半透明背景实例详解
- java利用反射映射两个不同对象的属性值
- 产品经理入职四部曲—带你顺利度过试用期
- 计算机进入桌面黑屏怎么办,电脑进入桌面后黑屏如何修复 电脑经常进入桌面之后黑屏的处理方法...
- Eclipse Theia:Eclipse的继承者?
- PyQt5编程-鼠标事件
- git merge 冲突解决
- 【系】微信小程序云开发实战坚果商城-扩展篇
热门文章
- php 两个数组 交集_两个数组的交集
- db2 空值转换函数_Hive常见函数的使用
- multisim中轻触开关在哪_现货供应轻触开关|品质确保|厂家直销
- java禁止js获取cookie_java中Cookie被禁用后Session追踪问题
- xargs 命令教程
- kafka和mysql内存机制_一文五分钟让你彻底理解Kafka架构原理
- 区块如何防篡改_深入浅出:一条数据是如何完成上链的
- html5画电池状态,HTML5的一个显示电池状态的API简介
- 配置文件bashrc与profile的区别
- MYSQL出错代码列表大全(中文)