一、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代理学习的更多相关文章

  1. nginx 反向代理学习

    目录 nginx 反向代理学习 一.正向代理和反向代理的区别 1.1正向代理 1.2 反向代理 二.nginx反向代理的使用 nginx 反向代理学习 一.正向代理和反向代理的区别 正向代理代理客户端 ...

  2. Nginx支持WebSocket反向代理-学习小结

    WebSocket是目前比较成熟的技术了,WebSocket协议为创建客户端和服务器端需要实时双向通讯的webapp提供了一个选择.其为HTML5的一部分,WebSocket相较于原来开发这类app的 ...

  3. nginx代理https站点(亲测)

    nginx代理https站点(亲测) 首先,我相信大家已经搞定了nginx正常代理http站点的方法,下面重点介绍代理https站点的配置方法,以及注意事项,因为目前大部分站点有转换https的需要所 ...

  4. Nginx 入门学习教程

    昨天听一个前同事说他们公司老大让他去研究下关于Nginx 方面的知识,我想了下Nginx 在如今的开发技术栈中应该会很大可能会用到,所以写篇博文记录总结下官网学习教程吧. 1. 什么是Nginx? 我 ...

  5. nginx简单学习(tomcat)

    一.负载均衡的简单配置 1.下载nginx 2.tomcat*2 配置不同的端口用于正常启动,在jsp中<%= session.getId()%>可以查看jSessionId,tomcat ...

  6. Nginx基础学习

    参考博客: http://www.2cto.com/os/201212/176520.html http://os.51cto.com/art/201111/304611.htm http://www ...

  7. go 通过nginx代理后获取用户ip

    go 如果使用自己的服务器,可以直接使用 net/http 来获取 func ip(w http.ResponseWriter, r *http.Request) { fmt.Println(r.Re ...

  8. 二、netcore跨平台之 Linux部署nginx代理webapi

    上一章,我们讲了在linux上安装netcore环境,以及让netcore在linux上运行. 这一章我们开始讲在linux上配置nginx,以及让nginx反向代理我们的webapi. 什么ngin ...

  9. 10分钟学会windows中iis搭建服务器集群实现负载均衡和nginx代理转发

    前言 我们之前聊过 10分钟搭建服务器集群--Windows7系统中nginx与IIS服务器搭建集群实现负载均衡:https://www.cnblogs.com/xiongze520/p/103087 ...

随机推荐

  1. [LintCode]计算两个数的交集(二)

    问题分析: 用两个指针分别遍历即可. 问题求解: public class Solution { /** * @param nums1 an integer array * @param nums2 ...

  2. 批量改名的多种方法stu_3_finished.jpg 去掉finished,stu_{1..20}_finished.jpg

    方法一:rename修改文件名 rename "finished" "" *.jpg [root@ob1 scripts]# rename "fini ...

  3. 怎么让一个div 悬浮在另一个div上

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. C++(1)C++类四个默认函数---构造函数、析构函数、拷贝函数、赋值函数

    C++构造函数和析构函数 默认构造函数指不带参数或者所有参数都有缺省值的构造函数!!! (1)构造函数.析构函数与赋值函数 构造函数.析构函数与赋值函数是每个类最基本的函数.它们太普通以致让人容易麻痹 ...

  5. WCF系列

    转自:1) http://www.cnblogs.com/zhili/p/WCFSummary.html 2)  http://www.cnblogs.com/artech/archive/2009/ ...

  6. 第二百九十二节,RabbitMQ多设备消息队列-Python开发

    RabbitMQ多设备消息队列-Python开发 首先安装Python开发连接RabbitMQ的API,pika模块 pika模块为第三方模块  对于RabbitMQ来说,生产和消费不再针对内存里的一 ...

  7. 深入了解Android蓝牙Bluetooth ——《总结篇》

    在我的上两篇博文中解说了有关android蓝牙的认识以及API的相关的介绍,蓝牙BLE的搜索,连接以及读取. 没有了解的童鞋们请參考: 深入了解Android蓝牙Bluetooth--<基础篇& ...

  8. CentOS服务器上搭建Gitlab安装步骤、中文汉化详细步骤、日常管理以及异常故障排查

    一, 服务器快速搭建gitlab方法 可以参考gitlab中文社区 的教程centos7安装gitlab:https://www.gitlab.cc/downloads/#centos7centos6 ...

  9. 【Rmarkdown rmysql】

    http://stackoverflow.com/questions/21167070/how-to-query-multiple-times-and-close-the-connection-at- ...

  10. 完美解决jQuery符号$与其他javascript 库、框架冲突的问题

    目前有大量的 javascript 开发框架,其中有一部分使用 $ 作为调用符号,这可能导致相互之间的冲突,而 jQuery 为解决这个问题,可以在 jQuery 导入时放弃 $ 使用权,届时 $ 则 ...