nginx 入门配置
这个星期公司的定期分享内容是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 入门配置的更多相关文章
- nginx入门配置
user www www; worker_processes 4; error_log logs/error.log; #pid logs/nginx.pid; events { worker_con ...
- 高性能Web服务器Nginx的配置与部署研究系列(1)-- 入门 hello work
简介: Nginx 是一个基于 BSD-like 协议.开源.高性能.轻量级的HTTP服务器.反向代理服务器以及电子邮件(SMTP.POP3.IMAP)服务器.Nginx 是由一个俄罗斯的名叫“Igo ...
- nginx入门与实战 安装 启动 配置nginx Nginx状态信息(status)配置 正向代理 反向代理 nginx语法之location详解
nginx入门与实战 网站服务 想必我们大多数人都是通过访问网站而开始接触互联网的吧.我们平时访问的网站服务 就是 Web 网络服务,一般是指允许用户通过浏览器访问到互联网中各种资源的服务. Web ...
- Nginx入门--从核心配置与动静分离开始
写在前面 优化我们项目,服务器部署,不仅仅可以是分布式,Nginx一样可以通过动静分离,负载均衡来减轻我们服务器的压力.Nginx的知识链,学习周期相对比较长,博主也是刚刚入门,这篇就先从实现基础的动 ...
- 学习nginx从入门到实践(四) 基础知识之nginx基本配置语法
nginx基本配置语法 1.http相关 展示每次请求的请求头: curl -v http://www.baidu.com 2.nginx日志类型 error.log. access.log log_ ...
- nginx入门到精通目录
1.nginx入门篇 nginx安装与基础配置 nginx优化配置分析与说明 nginx模块结构 2.nginx功能篇 配置nginx的gzip功能 配置nginx的rewrite功能 配置nginx ...
- Nginx 入门学习教程
昨天听一个前同事说他们公司老大让他去研究下关于Nginx 方面的知识,我想了下Nginx 在如今的开发技术栈中应该会很大可能会用到,所以写篇博文记录总结下官网学习教程吧. 1. 什么是Nginx? 我 ...
- Linux之nginx入门
nginx入门 详见可参考:https://www.cnblogs.com/tiger666/p/10239307.html?tdsourcetag=s_pctim_aiomsg 1. 常用的WEB框 ...
- nginx入门教程
nginx入门教程 一.概述 什么是nginx? Nginx (engine x) 是一款轻量级的Web 服务器 .反向代理服务器及电子邮件(IMAP/POP3)代理服务器. 什么是反向 ...
随机推荐
- MVC中登录页图片验证码总结
直接上代码了 using System;using System.Collections.Generic;using System.Drawing;using System.Drawing.Imagi ...
- LAMP学习小记
记录今天学习到的解决LAMP环境搭建的两个小问题: 问题1.xshell无法连接到虚拟机上的linux主机 解决方法: (1)进入网络配置文件: vi /etc/sysconfig/network-s ...
- 使用Python实现子区域数据分类统计
目录 前言 geopandas简介 子区域数据分类统计 总结 一.前言 最近碰到一个需求,需要统计某省内的所有市的某数据分布情况信息.现有该省的数据分布情况以及该省的行政区划数据.我通过 ...
- 更新几篇之前写在公众号上的文章:线性可分时SVM理论推导;关联分析做捆绑销售和推荐;分词、去停用词和画词云
适合阅读人群:有一定的数学基础. 这几篇文章是16年写的,之前发布在个人公众号上,公众号现已弃用.回过头来再看这几篇文章,发现写的过于稚嫩,思考也不全面,这说明我又进步了,但还是作为学习笔记记在这里了 ...
- OSS最新进度汇报(2.25)
OSS系列最新进度情况如下:一. OSS.Social进度 1. 客服接口升级至新客服接口 2. BaseRecMsg中RecMsg字符串类型修改为xml类型 3. 添加Redis缓存注册实现,代码见 ...
- JS事件绑定深入
W3C很好地解决了覆盖问题.相同函数屏蔽的问题.this传递问题.添加额外方法不被覆盖等问题. 但是IE8之前的版本并不支持,IE9已完全支持了. IE和W3C在事件绑定上存在很多差异,我们以冒泡和捕 ...
- MySQL Sniffer
MySQL Sniffer 是360开源的一个基于 MySQL 协议的抓包工具, 能实时抓取客户端端请求,并格式化输出操作语句,操作十分简单.对于问题的定位,操作的审核是个不错的利器. Github地 ...
- 通过udev创建ASM共享磁盘(RAC)
OS:RedHat EL6.0 Oracle: Oracle 11gR2 在Oracle 11gR2,构建RAC时可以通过ASM创建asm disk,但是需要安装asmlib相关软件:对于RedH ...
- 【2-23】分支语句(switch…case)及循环语句
Switch-case分支语句与if语句作用相同,但需将情况都罗列出比较麻烦所以不常用. 其基本结构是: Switch(一个变量值) { Case 值1:要执行的代码段:break; Case 值2: ...
- Convert Sorted Array to Binary Search Tree & Convert Sorted List to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Su ...