Nginx developed specifically for performance optimization, its biggest advantage is its low stability and consumption of system resources, as well as high processing capacity http concurrent connections, a single physical server can support concurrent requests 20,000 to 50,000, is the case, providing a large number of social networking, news, e-commerce and web hosting, and service companies have chosen to provide Nginx web services, mainland China use nginx web site users are: Sina, Netease, Tencent, another well-known micro-blog Plurk also use nginx .
Nginx is a very high-performance Web cattle and reverse proxy server, which has had a lot of very superior characteristics:
高并发连接:官方测试能支撑5万并发连接,在实际生产环境中跑到2,~3W并发连接。
内存消耗少:在3W并发连接下,开启的10个NGINX进程才消耗150M内存(15M*10=150M)
配置文件非常简单:风格跟程序一样通俗易懂。
成本低廉:Nginx作为开源软件,可以免费使用,而购买F5 BIG-IP、NetScaler等硬件负载均衡交换机则需要十多万至几十万人民币。
支持rewrite重写规则:能够根据域名、URL的不同,将HTTP请求分发到不同的后端服务器群组。
内置的健康检查功能:如果Nginx Proxy后端的后台web服务器宕机了,不会影响前端访问。
节省带宽:支持GZIP压缩,可以添加浏览器本地缓存的Header头。
稳定性高:用于反向代理,宕机的概率微乎其微。
Nginx theoretical knowledge in which not much to say, here's get down to build Nginx web server:
1, a CentOS 7 server;
2, a CentOS 7 system tray;
3, the package need to use, here we are ready good one, extract links:
extraction connection
First, the site began to build Nginx:
1, mount the CD-ROM system initialization yum source
[root@Centos02 ~]# mount /dev/cdrom /mnt/ #挂载系统光盘
[root@centos02 ~]# mkdir /etc/yum.repos.d/bak #创建系统yum备份目录
[root@centos02 ~]# mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/bak/
#将系统自带的yum配置文件以Centos-开头的所有文件复制到bak目录中
[root@centos02 ~]# vim /etc/yum.repos.d/local.repo #创建yum配置文件
[local]
name=centos
baseurl=file:///mnt
enabeld=1
gpgcheck=0
2, install nginx
[root@centos02 ~]# yum -y install pcre pcre-devel zlib-devel #安装依赖程序
[root@centos02 ~]# umount /mnt/ #卸载系统光盘,切换软件包光盘
[root@centos02 ~]# mount /dev/cdrom /mnt/ #挂载软件包光盘
[root@centos02 ~]# tar zxvf /mnt/nginx-1.6.0.tar.gz -C /usr/src/
#将mnt目录中程序解压缩到/src
[root@centos02 ~]# useradd -M -s /sbin/nologin nginx # 创建管理的nginx的用户
[root@centos02 ~]# cd /usr/src/nginx-1.6.0/ #编译安装nginx
[root@centos02 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@centos02 nginx-1.6.0]# make && make install #编译安装nginx
[root@centos02 nginx-1.6.0]# ln -s /usr/local/nginx/sbin/nginx* /usr/local/sbin/
#优化执行命令
[root@centos02 ~]# echo "www.benet.com" > /usr/local/nginx/html/index.html
#修改新页面覆盖旧页面
[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf #设置Nginx最大并发
12 events {
13 worker_connections 4096;
14 }
Second, configure nginx web hosting
[root@Centos02 ~]# vim /usr/local/nginx/conf/nginx.conf
#nginx配置虚拟主机www.benet.com
35 server { #Server表示虚拟主机
36 listen 80; #虚拟主机监听端口
37 server_name www.benet.com; #虚拟主机域名
38 charset utf-8; #支持字符编码
39 access_log logs/www.benet.com.access.log;
#成功日志位置/usr/local/nginx/logs/
40 error_log logs/www.benet.com.error.log; #错误日志/usr/local/nginx/logs/
41 location / {
42 root /var/www/benetcom/; #网站根目录(默认/usr/local/nginx/html/)
43 index index.html index.htm; #网站主页index.html或者index.htm
44 }
45 }
[root@Centos02 ~]# mkdir -p /var/www/benetcom
#创建www.benet.com虚拟主机网站根目录
[root@Centos02 ~]# echo "www.benet.com" > /var/www/benetcom/index.html
#创建www.benet.com虚拟主机主页
[root@Centos02 ~]# vim /usr/local/nginx/conf/nginx.conf
#配置www.accp.com虚拟主机
47 server { #Server表示虚拟主机
48 listen 80; #虚拟主机监听端口
49 server_name www.accp.com; #虚拟主机域名
50 charset utf-8; #支持字符编码
51 access_log logs/www.accp.com.access.log;
#成功日志位置/usr/local/nginx/logs/
52 error_log logs/www.accp.com.error.log; #错误日志/usr/local/nginx/logs/
53 location / {
54 root /var/www/accpcom/; #网站根目录(默认/usr/local/nginx/html/)
55 index index.html index.htm; #网站主页index.html或者index.htm
56 }
57 }
[root@Centos02 ~]# mkdir -p /var/www/accpcom
#创建www.accp.com虚拟主机网站根目录
[root@Centos02 ~]# echo "www.accp.com" > /var/www/accpcom/index.html
#设置www.accp.com虚拟主机网站主页
Third, start Nginx
[root@centos02 ~]# nginx #启动nginx
[root@centos02 ~]# killall -s QUIT nginx #停止nginx
[root@centos02 ~]# killall -s HUP nginx #重新启动nginx
Fourth, the client-side validation Nginx, ensure that the client and server centos 7 network is interconnected, otherwise white torn, (where there is no need to manually add DNS set up host file, and subsequent updates LNMP LAMP re detailed configuration)
1, add a host file
2, Client Access