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 ...
随机推荐
- CAS (4) —— CAS浏览器SSO访问顺序图详解(CAS Web Flow Diagram by Example)
CAS (4) -- CAS浏览器SSO访问顺序图详解(CAS Web Flow Diagram by Example) tomcat版本: tomcat-8.0.29 jdk版本: jdk1.8.0 ...
- [Django学习]入门
1. 搭建开发环境 安装django 建议安装1.8.2版本,这是一个稳定性高.使用广.文档多的版本 pip install django==1.8.2 查看版本:进入python shell,运行如 ...
- Web API(二):Web API概述
一.什么是API API(Application Programming Interface)即应用程序编程接口,是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能 ...
- C++中 char *s 和 char s[] 的区别
原因 刚好看到给main传递参数,书上(C++Primer)说“ int main(int argc, char *argv[])也可以写成 int main(int argc, char **arg ...
- 第二百九十二节,RabbitMQ多设备消息队列-Python开发
RabbitMQ多设备消息队列-Python开发 首先安装Python开发连接RabbitMQ的API,pika模块 pika模块为第三方模块 对于RabbitMQ来说,生产和消费不再针对内存里的一 ...
- PHP简单的图片上传
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- linux环境下,清空history中记录的历史命令
需求描述: 今天在数据库主机上操作,通过history看到有刚操作过的历史记录,想把这个清除了, 但是,还不影响后续的命令记录,所以查了下,在此记录. 操作过程: 1.通过history -c命令,完 ...
- Codeforces Round #277.5 (Div. 2)部分题解
A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- git for c#, commit本地,pushserver
//ok private static void push() { string wkDir = @"E:\DotNet2010\单位project\Git.Client\lib2Test\ ...
- TestNG入门教程
阅读目录 TestNG介绍 在Eclipse中在线安装TestNG 在Eclipse中离线安装Testng TestNG最简单的测试 TestNG的基本注解 TestNG中如何执行测试 使用testt ...