nginx可以重新加载文件的。我们直接运行:nginx -s reload

配置文件有没有问题,可以直接输入:nginx -t

nginx -s stop就可以关闭

但有时我们就不想它挂的时候访问另外一个,而只是希望一个服务器访问的机会比另外一个大,使用weight

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#gzip  on;
 
    #一个服务器挂了,多配置一个jetty,weight=数字来指定,数字越大,表明请求到的机会越大
 
    upstream local_tomcat { 
            server localhost:8080 weight=1;
            server localhost:9999 weight=5;
    server{
        listen       8030;
        server_name  localhost:8080;
        #charset koi8-r;
       #access_log  logs/host.access.log  main;
        location / {proxy_pass http://local_tomcat;} 
        ##......其他省略
        #过滤不同的jsp和静态html页面
        #location / {  proxy_pass http://localhost:8080;}
        #location ~ .jsp$ {    proxy_pass http://localhost:8080;} 
        #location ~ .(html|js|css|png|gif)$ {  root D:/apache-tomcat-7.0.77/webapps/ROOT;}
        error_page   500 502 503 504  /50x.html;
 
        location = /50x.html {
 
            root   html;
 
        }
 
    }

<wiz_tmp_tag class="wiz-block-scroll">

 

1、nginx能做反向代理,那么什么是反向代理呢,举个栗子,我想在本地使用 www.mickey.com 的域名去访问 www.taobao.com。那么这个时候我们就可以通过nginx去实现。

2、nginx能实现负载均衡,什么是负载均衡呢?就是我的项目部署在不同的服务器上,但是通过统一的域名进入,nginx则对请求进行分发,减轻了服务器的压力。

3、作为安全隔离的作用;

4、解决跨域问题。

5、缓存静态文件,加快访问速度。

修改nginx.conf 配置文件,启用 upstream 负载均衡 tomcat Cluster,默认使用轮询方式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
upstream site { 
    server localhost:8080;
    server localhost:9090;
 
server {
    listen       80;
    server_name  localhost;
 
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
 
    location / {
        #root   /usr/share/nginx/html;
        #index  index.html index.htm;
        index  index_tel.jsp index.jsp index.html index.htm ; 
        proxy_redirect          off;   
        proxy_set_header        Host            $host;   
        proxy_set_header        X-Real-IP       $remote_addr;   
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;   
        client_max_body_size    10m;   
        client_body_buffer_size 128k;   
        proxy_buffers           32 4k; 
        proxy_connect_timeout   3;   
        proxy_send_timeout      30;   
        proxy_read_timeout      30;  
            proxy_pass http://site;
 
    }

<wiz_tmp_tag class="wiz-block-scroll">

 

测试:

1、访问 http://10.129.221.70:8080 直接请求到tomcat_1服务器,显示 “ response from tomcat_1 ”, session 值为 ‘56E2FAE376A47F1C0961D722326B8423’;

2、访问 http://10.129.221.70:9090 直接请求到tomcat_2服务器,显示 “ response from tomcat_2 ”, session 值为 ‘56E2FAE376A47F1C0961D722326B8423’;

3、访问 http://10.129.221.70 (默认80端口)请求到 nginx 反向代理到指定Web服务器,由于默认使用轮询负载方式,反复刷新页面显示的内容在“ response from tomcat_1 ” 和 “ response from tomcat_2 ”之间切换,但 session 值保持为 ‘56E2FAE376A47F1C0961D722326B8423’;

4、使用 redis-cli 连接 redis 服务器,查看会显示有 “56E2FAE376A47F1C0961D722326B8423” key的 session 数据,value为序列化数据。

Nginx基本配置和作用的更多相关文章

  1. Nginx Location配置总结

    Nginx Location配置总结 语法规则: location [=|~|~*|^~] /uri/ { - }= 开头表示精确匹配^~ 开头表示uri以某个常规字符串开头,理解为匹配 url路径即 ...

  2. nginx缓存配置的操作记录梳理

    web缓存位于内容源Web服务器和客户端之间,当用户访问一个URL时,Web缓存服务器会去后端Web源服务器取回要输出的内容,然后,当下一个请求到来时,如果访问的是相同的URL,Web缓存服务器直接输 ...

  3. 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解

    看了很多nginx的配置,好像都忽略了ip直接访问web的问题,不利于SEO优化,所以我们希望可以避免直接用IP访问网站,而是域名访问,具体怎么做呢,看下面. 官方文档中提供的方法: If you d ...

  4. Nginx安装配置(转)

    Nginx 安装配置 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/ ...

  5. nginx location配置

    nginx location配置   location在nginx中起着重要作用,对nginx接收到的请求字符串进行处理,如地址定向.数据缓存.应答控制.代理转发等location语法location ...

  6. nginx的配置总结

    总体而言,nginx的配置比起apache来是要简洁很多,而言容易理解得多的,另外官网的文档也十分的简洁易懂.我们先看一个简化版的配置文件nginx.conf: #user nobody; worke ...

  7. nginx性能配置参数说明:

    nginx的配置:main配置段说明一.正常运行的必备配置: 1.user username [groupname]; 指定运行worker进程的用户和组 2.pid /path/to/pidfile ...

  8. nginx的配置与安装

    说说在Linux系统下安装配置Nginx的详细过程. 1. 从Nginx官网下载Nginx.目前最新的稳定版为:1.6.2. 2. 将下载下来的Nginx上传到/opt/nginx目录下.运行“tar ...

  9. 记一次Nginx的配置

    记第一次Nginx的配置 Nginx 首先了解到Nginx是干什么的?它有哪些作用?比较常用到的基础功能有反向代理.负载均衡.正向代理.http服务器.这次部署用到的就是反向代理. 反向代理就是指在目 ...

随机推荐

  1. linux下的C语言开发(网络编程)

    http://blog.csdn.net/feixiaoxing/article/details/7259675 [ 声明:版权所有,欢迎转载,请勿用于商业用途.  联系信箱:feixiaoxing ...

  2. .Net ToString Format [转]

    源文 :http://blog.csdn.net/luyifeiniu/article/category/25663/2 stringstr1 =string.Format("{0:N1}& ...

  3. 算法之美--3.2.2 MP算法

    这块硬骨头,放在这里半年的时间了,一直没有动,今天周末看看,书上把过程写的比较详细,自己基本也看懂了,但是对代码本身的编写还是比较生疏,要经常复习,估计才能看透,后面有看了kmp;这两者之间的关系也是 ...

  4. [Algorithm] Write a Depth First Search Algorithm for Graphs in JavaScript

    Depth first search is a graph search algorithm that starts at one node and uses recursion to travel ...

  5. react 路由传参

    今天,我们要讨论的是react router中Link传值的三种表现形式.分别为通过通配符传参.query传参和state传参. ps:进入正题前,先说明一下,以下的所有内容都是在react-rout ...

  6. Name和:Name

    http://www.cnblogs.com/tianyutingxy/archive/2011/02/23/1962078.html http://www.tuicool.com/articles/ ...

  7. jquery easyui 全部图标

    所有的图标在 jquery-easyui-1.2.6\themes\icons 目录下, 在icon.css定义的如何引用 jquery-easyui-1.2.6/themes/icon.css .i ...

  8. cygwin配置个人环境,android模拟器root映象和Babun

    零.Windows命令行个人设置 @echo off :: Temporary system path at cmd startup ::set PATH=%PATH%;"C:\Progra ...

  9. Java UUID 生成(转载)

    来自:http://www.cnblogs.com/jdonson/archive/2009/07/22/1528466.html 基本原理:GUID是一个128位长的数字,一般用16进制表示.算法的 ...

  10. 多项式相乘快速算法原理及相应C代码实现---用到fft

    最近认真研究了一下算法导论里面的多项式乘法的快速计算问题,主要是用到了FFT,自己也实现了一下,总结如下. 1.多项式乘法 两个多项式相乘即为多项式乘法,例如:3*x^7+4*x^5+1*x^2+5与 ...