nginx代理学习
一、windows下nginx代理ftp服务器
我所在的开发环境里,nginx和ftp在同一台服务器。
ftp根目录:
nginx的配置:
在nginx.conf中加入:
server { listen ; server_name localhost; location / { root C:/FTPRoot; index *.*; add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; } }
然后重新加载配置文件即可,参考:https://www.cnblogs.com/qianzf/p/6809427.html。
二、nginx配置:通过端口进行负载均衡
#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 9004; location /igt { root /usr/local/nginx/webapps; index index.html; } } upstream 8080tomcat { server 10.11.12.61:8080 weight=1; server 10.11.12.62:8080 weight=1; } server { listen 8080; server_name localhost; location / { root html; index index.html index.htm; proxy_pass http://8080tomcat; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } upstream 9080tomcat { server 10.11.12.105:9080 weight=1; server 10.11.12.106:9080 weight=1; } server { listen 9080; server_name localhost; location / { root html; index index.html index.htm; proxy_pass http://9080tomcat; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
这其中,根据端口会分发到不同的后端集群中。
三、nginx配置前后端分离项目
一般的项目中,前后端分离。前端是纯粹的html,直接放nginx。前端项目中,会指定后端的地址。
我们可以将后端的地址,指定为nginx的ip+后端服务的端口。
然后,在nginx中,再像上述第二节那样配置端口转发。
本例中,nginx的ip为:10.11.12.107
1、配置前端
server { listen 9004; location /igt { root /usr/local/nginx/webapps; index index.html; } }
前端项目的位置如下:
2、在前端项目中配置后端服务的url
3、配置后端服务
upstream 9080tomcat { server 10.11.12.105:9080 weight=1; server 10.11.12.106:9080 weight=1; } server { listen 9080; server_name localhost; location / { root html; index index.html index.htm; proxy_pass http://9080tomcat; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
nginx代理学习的更多相关文章
- nginx 反向代理学习
目录 nginx 反向代理学习 一.正向代理和反向代理的区别 1.1正向代理 1.2 反向代理 二.nginx反向代理的使用 nginx 反向代理学习 一.正向代理和反向代理的区别 正向代理代理客户端 ...
- Nginx支持WebSocket反向代理-学习小结
WebSocket是目前比较成熟的技术了,WebSocket协议为创建客户端和服务器端需要实时双向通讯的webapp提供了一个选择.其为HTML5的一部分,WebSocket相较于原来开发这类app的 ...
- nginx代理https站点(亲测)
nginx代理https站点(亲测) 首先,我相信大家已经搞定了nginx正常代理http站点的方法,下面重点介绍代理https站点的配置方法,以及注意事项,因为目前大部分站点有转换https的需要所 ...
- Nginx 入门学习教程
昨天听一个前同事说他们公司老大让他去研究下关于Nginx 方面的知识,我想了下Nginx 在如今的开发技术栈中应该会很大可能会用到,所以写篇博文记录总结下官网学习教程吧. 1. 什么是Nginx? 我 ...
- nginx简单学习(tomcat)
一.负载均衡的简单配置 1.下载nginx 2.tomcat*2 配置不同的端口用于正常启动,在jsp中<%= session.getId()%>可以查看jSessionId,tomcat ...
- Nginx基础学习
参考博客: http://www.2cto.com/os/201212/176520.html http://os.51cto.com/art/201111/304611.htm http://www ...
- go 通过nginx代理后获取用户ip
go 如果使用自己的服务器,可以直接使用 net/http 来获取 func ip(w http.ResponseWriter, r *http.Request) { fmt.Println(r.Re ...
- 二、netcore跨平台之 Linux部署nginx代理webapi
上一章,我们讲了在linux上安装netcore环境,以及让netcore在linux上运行. 这一章我们开始讲在linux上配置nginx,以及让nginx反向代理我们的webapi. 什么ngin ...
- 10分钟学会windows中iis搭建服务器集群实现负载均衡和nginx代理转发
前言 我们之前聊过 10分钟搭建服务器集群--Windows7系统中nginx与IIS服务器搭建集群实现负载均衡:https://www.cnblogs.com/xiongze520/p/103087 ...
随机推荐
- uboot中bootargs实现
setup.h通过宏定义实现了bootargs传递参数到内核,值得以后编程学习. include/asm-arm/setup.h 14 * NOTE: 15 * This file contai ...
- javascript那些不应该忽视的细节
1.null与Object.prototype使用typeof操作符结果都是object,但他们都不是Object的实例. typeof null // object null instanceof ...
- iscsi线缆
- hdu2896 病毒侵袭 AC自动机入门题 N(N <= 500)个长度不大于200的模式串(保证所有的模式串都不相同), M(M <= 1000)个长度不大于10000的待匹配串,问待匹配串中有哪几个模式串,
/** 题目:hdu2896 病毒侵袭 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2896 题意:N(N <= 500)个长度不大于200的模式串 ...
- USB2.0学习笔记连载(三):通用USB驱动程序解析
对于USB驱动的开发,读者可以使用Windows DDK.DriverStudio等多种开发工具来实现USB的驱动,但是驱动程序的开发过程都比较复杂,而且很容易致使USB主机内存泄露而死机.那么对于笔 ...
- HttpClient学习之 客户端HTTP编程入门
说明 本文存在的原因,是想深入的学习下HttpClient.对应的网址是: http://hc.apache.org/httpcomponents-client-4.5.x/primer.html h ...
- (转)windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTime
执行 10000000 次, 耗时 2258,369 微秒 QueryPerformanceCounter 执行 10000000 次, 耗时 26,347 微秒 GetTickCoun ...
- (转)非阻塞Connect对于select时应注意问题
对于面向连接的socket类型(SOCK_STREAM,SOCK_SEQPACKET)在读写数据之前必须建立连接,首先服务器端socket必须在一个客户端知道的地址进行监听,也就是创建socket之后 ...
- Oracle行列转换的思考与总结
最近几天一直在弄Oracle-SQL的问题,涉及到了一些平时没有用到的东西,也因此而在这里郁闷了好久.现在问题得到了解决虽说不算完美.但是还是和大家一起分享一下. 行列转换之一:sum(case wh ...
- 存储过程不返回记录集导致ADO程序出错
HRESULT _hr = get_adoEOF(&_result); IsEOF()函数如下:其中ADOCG::_RecordsetPtr m_pRecordset; BOOL IsEOF( ...