这个星期公司的定期分享内容是Nginx,于是就要写作业了。

一、动静分离

1、下载Windows 版本的Nginx,解压,放到C盘下。进入目录,然后按然shift键右键,打开命令行,输入:

start nginx

2、访问localhost,启动成功。

3、然后做如下配置:

4、启动tomcat,访问localhost:8080:

5、重启nginx:

nginx -s reload

6、访问localhost/index.jsp,静态文件全部找不到,页面跑版。

7、把tomcat的静态文件放到目录下, 再次访问localhost/index.jsp:

8、一个简单的动静分享就做完啦。

二、绑定多个域名

1、在配置文件和server同级的位置加上这一句

    include C:/nginx-1.9.1/conf/vhosts/*.conf;

2、在conf目录下新建一个vhosts文件夹,里面新建两个文件:

tomcat.conf

    server {
listen 80;
server_name tomcat.ice.com; #charset koi8-r; #access_log logs/host.access.log main; 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;
#}
}

star.conf

    server {
listen 80;
server_name star.ice.com; #charset koi8-r; #access_log logs/host.access.log main; location / {
root "H:/repository/svn/4";
index index.html index.htm;
} #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;
#}
}

3、在host文件中加下以下代码:

127.0.0.1       star.ice.com
127.0.0.1 tomcat.ice.com

4、重启nginx

nginx -s reload

5、分别访问star.ice.com和tomcat.ice.com:

6、打完收工,关闭nginx:

nginx -s quit

三、负载均衡

1、搭三个服务器:

192.168.1.104;
127.0.0.1:8080;
192.168.188.132:8080;

2、配置nginx.conf, 没有用的已经省略掉了(这里可以配置各种策略,具体参考官方文档吧):

http {

	upstream  www.ice.com {
server 192.168.1.104;
server 127.0.0.1:8080;
server 192.168.188.132:8080;
} server
{
listen 80;
server_name www.ice.com; location / {
proxy_pass http://www.ice.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
} }

3、重新启动nginx:

nginx -s reload

4,往host文件中加入

127.0.0.1        www.ice.com

5、打开www.ice.com,可以刷出以下三个页面:

6、负载均衡的最基本配置也做完啦。。。

nginx 入门配置的更多相关文章

  1. nginx入门配置

    user www www; worker_processes 4; error_log logs/error.log; #pid logs/nginx.pid; events { worker_con ...

  2. 高性能Web服务器Nginx的配置与部署研究系列(1)-- 入门 hello work

    简介: Nginx 是一个基于 BSD-like 协议.开源.高性能.轻量级的HTTP服务器.反向代理服务器以及电子邮件(SMTP.POP3.IMAP)服务器.Nginx 是由一个俄罗斯的名叫“Igo ...

  3. nginx入门与实战 安装 启动 配置nginx Nginx状态信息(status)配置 正向代理 反向代理 nginx语法之location详解

    nginx入门与实战 网站服务 想必我们大多数人都是通过访问网站而开始接触互联网的吧.我们平时访问的网站服务 就是 Web 网络服务,一般是指允许用户通过浏览器访问到互联网中各种资源的服务. Web ...

  4. Nginx入门--从核心配置与动静分离开始

    写在前面 优化我们项目,服务器部署,不仅仅可以是分布式,Nginx一样可以通过动静分离,负载均衡来减轻我们服务器的压力.Nginx的知识链,学习周期相对比较长,博主也是刚刚入门,这篇就先从实现基础的动 ...

  5. 学习nginx从入门到实践(四) 基础知识之nginx基本配置语法

    nginx基本配置语法 1.http相关 展示每次请求的请求头: curl -v http://www.baidu.com 2.nginx日志类型 error.log. access.log log_ ...

  6. nginx入门到精通目录

    1.nginx入门篇 nginx安装与基础配置 nginx优化配置分析与说明 nginx模块结构 2.nginx功能篇 配置nginx的gzip功能 配置nginx的rewrite功能 配置nginx ...

  7. Nginx 入门学习教程

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

  8. Linux之nginx入门

    nginx入门 详见可参考:https://www.cnblogs.com/tiger666/p/10239307.html?tdsourcetag=s_pctim_aiomsg 1. 常用的WEB框 ...

  9. nginx入门教程

    nginx入门教程 一.概述    什么是nginx?   Nginx (engine x) 是一款轻量级的Web 服务器 .反向代理服务器及电子邮件(IMAP/POP3)代理服务器.   什么是反向 ...

随机推荐

  1. event.target的第一次

    今天在学习其他人代码的时候见到了event.target.nodeName,event.target.dataset.刚开始是一头雾水,便google一下.发现大多数给出的词条都是有关jQuery事件 ...

  2. jQuery中.bind() .live() .delegate() .on()的区别 和 三种方式写光棒事件 动画

    地狱的镰刀 bind(type,[data],fn) 为每个匹配元素的特定事件绑定事件处理函数. $("a").bind("click",function(){ ...

  3. Linux-7.2+LNMP+zabbix-3.2.1

    LNMP+zabbix-3.2.1 一.zabbix服务端部署 1.解压 yum –y install bzip2 tar -xf nginx-1.10.1.tar.gz tar -xf php-5. ...

  4. 解析java泛型(二)

    上篇我们简单的介绍了java中泛型的最基本的内容,知道了什么是泛型以及泛型对我们的程序编写有什么好处,最后一类型限定收尾.本篇将从类型限定开始阐述java泛型中很重要的概念:通配符 一.何为通配符   ...

  5. c++动态库与静态库

    windows下: 在进行库创建的时候会用到导出符号,在函数,类的声明处直接指出. 静态库:用的时候通常将 #pagram (lib,"name"),包含头文件,可以使用任何导出类 ...

  6. 一道面试题引发的对javascript类型转换的思考

    最近群里有人发了下面这题:实现一个函数,运算结果可以满足如下预期结果: add(1)(2) // 3 add(1, 2, 3)(10) // 16 add(1)(2)(3)(4)(5) // 15 对 ...

  7. mfc--使用ShellExecute打开另一个可执行程序

    ShellExecute(sFile [, vArguments] [, vDirectory] [, vOperation] [, vShow]) ShellExecute(NULL,"o ...

  8. 深入理解 JavaScript 异步系列(3)—— ES6 中的 Promise

    第一部分,Promise 加入 ES6 标准 原文地址 http://www.cnblogs.com/wangfupeng1988/p/6515855.html 未经作者允许不得转载! 从 jquer ...

  9. Linux进程管理详解

    何谓进程?进程,就是正在执行的一个程序或命令,每一个进程都是一个运行实体,有自己的地址空间,并占用一定的系统资源.简而言之,进程就是运行中的程序.在Linux中,诸如ls等命令都是进程,只不过某些命令 ...

  10. ActiveMQ学习系列(四)----消息持久化到mysql

    前记:目前学习还比较杂乱,还未找到系统化地学习ActiveMq的方法.在网上看到消息持久化的demo,了解了一下,在此记录. 一.目前ActiveMq支持的持久化方法 url:http://activ ...