nginx拜访操控

关于Nginx

一款高性能,轻量级web服务软件

稳定性高
体系资源耗费低
对HTTP并发联接的处理才华高

  • 单台物理服务器可支撑30000~50000个并发央求

环境

一台Linux服务器(192.168.13.128)
一台win10查验机

一,在Windows大将LAMP所需紧缩软件包同享出来(此处如有问题请看之前的博客与之相类似的文章)

nginx拜访操控

二,在Linux上运用长途同享获取文件并挂载到mnt目录下

[root@localhost ~]# smbclient -L //192.168.100.3/   ##长途同享拜访
Enter SAMBAroot's password:
Sharename       Type      Comment
---------       ----      -------
LAMP-C7         Disk
[root@localhost ~]# mount.cifs //192.168.100.3/LAMP-C7 /mnt  ##挂载到/mnt目录下

三,编译设备Nginx

1,解压源码包到/opt下,并检查

[root@localhost ~]# cd /mnt    ##切换到挂载点目录
[root@localhost mnt]# ls
apr-1.6.2.tar.gz                  Discuz_X2.5_SC_UTF8.zip  LAMP-php5.6.txt
apr-util-1.6.0.tar.gz             error.png                mysql-5.6.26.tar.gz
awstats-7.6.tar.gz                httpd-2.4.29.tar.bz2     nginx-1.12.0.tar.gz
cronolog-1.6.2-14.el7.x86_64.rpm  kali.jpg                 php-5.6.11.tar.bz2
[root@localhost mnt]# tar zxvf nginx-1.12.0.tar.gz -C /opt   ##解压Nginx源码包到/opt下
[root@localhost mnt]# cd /opt/    ##切换到解压的目录下
[root@localhost opt]# ls
nginx-1.12.0  rh

2,设备编译需求的环境组件包

[root@localhost opt]# yum -y install 
gcc                                        //c言语
gcc-c++                         //c++言语
pcre-devel                      //pcre言语东西
zlib-devel                       //数据紧缩用的函式库

3,创立程序用户nginx并编译Nginx

[root@localhost opt]# useradd -M -s /sbin/nologin nginx  ##创立程序用户,安全不行登陆状况
[root@localhost opt]# id nginx
uid=1001(nginx) gid=1001(nginx) 组=1001(nginx)
[root@localhost opt]# cd nginx-1.12.0/                 ##切换到nginx目录下
[root@localhost nginx-1.12.0]# ./configure          ##装备nginx
> --prefix=/usr/local/nginx         ##设备途径
> --user=nginx                          ##用户名
> --group=nginx                        ##用户组
> --with-http_stub_status_module     ##状况核算模块

4,编译和设备

[root@localhost nginx-1.12.0]# make     ##编译
...
[root@localhost nginx-1.12.0]# make install   ##设备
...

5,优化nginx建议脚本,以便于体系辨认

[root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/  ##创立软联接让体系辨认nginx建议脚本
[root@localhost nginx]# nginx -t       ##检查装备文件的语法问题
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx]# nginx      ##翻开ngnix
[root@localhost nginx]# netstat -ntap | grep 80     ##检查端口,nginx现已翻开
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      39620/nginx: master
[root@localhost nginx]# systemctl stop firewalld.service    ##封闭防火墙
[root@localhost nginx]# setenforce 0 

6,设备elinks网页查验东西,并进行查验

[root@localhost nginx]# yum install elinks -y    ##设备elinks软件
[root@localhost nginx]# elinks http://localhost  ##查验nginx网页

nginx拜访操控

7,服务翻开重载以及封闭

[root@localhost nginx]# killall -s QUIT nginx   ##连续 或许运用killall -3 nginx
[root@localhost nginx]# killall -s HUP nginx    ##重启 或许运用killall -1 nginx
[root@localhost nginx]# nginx                         ##翻开

8,制造处理脚本,便于运用service处理运用

[root@localhost nginx]# cd /etc/init.d/   ##切换到建议装备文件目录
[root@localhost init.d]# ls
functions  netconsole  network  README
[root@localhost init.d]# vim nginx         ##修改建议脚本文件
#!/bin/bash
# chkconfig: - 99 20                                    ##注释信息
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"           ##设置变量为nginx指令文件
PIDF="/usr/local/nginx/logs/nginx.pid"       ##设置变量PID文件 进程号为5346
case "$1" in
start)
$PROG                                              ##翻开服务
;;
stop)
kill -s QUIT $(cat $PIDF)                    ##封闭服务
;;
restart)                                                  ##重启服务
$0 stop
$0 start
;;
reload)                                                  ##重载服务
kill -s HUP $(cat $PIDF)
;;
*)                                                           ##过失输入提示
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
[root@localhost init.d]# chmod +x /etc/init.d/nginx    ##给建议脚本实施权限
[root@localhost init.d]# chkconfig --add nginx          ##增加到service处理器中
[root@localhost init.d]# service nginx stop                ##就能够正常的运用service操控nginx
[root@localhost init.d]# service nginx start

Nginx的拜访状况核算

  • 启用HTTP_STUB_STATUS状况核算模块
  • nginx -V能够检查已设备的Nginx是否包括核算模块

一,修改nginx装备文件

[root@localhost ~]# cd /usr/local/nginx/conf     ##切换到装备文件目录
[root@localhost conf]# vim nginx.conf              ##修改Nginx装备文件
server {
listen       80;
server_name  www.kgc.com;        ##指明一个域名
charset utf-8;                                 ##中文字符集
#access_log  logs/host.access.log  main;
location / {
root   html;
index  index.html index.htm;
}
location /status {                           ##增加状况核算
stub_status on;
access_log off;
}

二,设备DNS服务器做域名解析

1,设备bind服务

[root@localhost conf]# yum install bind -y   ##设备DNS服务

2,装备主装备文件/etc/named.conf

 [root@localhost conf]# vim /etc/named.conf   ##主装备文件
options {
listen-on port 53 { any; };      ##将本机监听为悉数
listen-on-v6 port 53 { ::1; };
directory       "/var/named";
dump-file       "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
recursing-file  "/var/named/data/named.recursing";
secroots-file   "/var/named/data/named.secroots";
allow-query     { any; };      ##容许悉数

3,装备区域装备文件(etc/named.rfc1912.zones)

[root@localhost conf]# vim /etc/named.rfc1912.zones  ##装备区域装备文件
zone "localhost" IN {             ##复制模板到下面
type master;
file "named.localhost";
allow-update { none; };
};
zone "kgc.com" IN {              ##修改localhost为kgc.com
type master;
file "kgc.com.zone";      ##创立区域数据装备文件
allow-update { none; };
};

4,修改区域数据装备文件( kgc.com.zone)

[root@localhost conf]# cd /var/named
[root@localhost named]# cp -p named.localhost kgc.com.zone
##复制模板为kgc.com.zone
[root@localhost named]# vim kgc.com.zone  ##修改区域数据装备文件
$TTL 1D
@       IN SOA  @ rname.invalid. (
0       ; serial
1D      ; refresh
1H      ; retry
1W      ; expire
3H )    ; minimum
NS      @
A       127.0.0.1
www IN  A       192.168.13.128   ##删去ipv6 增加域名解析地址为本机

5,封闭防火墙并翻开服务

[root@localhost named]# systemctl start named   ##翻开dns服务
[root@localhost named]# systemctl stop firewalld.service    ##封闭防火墙
[root@localhost named]# setenforce 0   ##封闭增强功用

6,运用win10查验机来查验

nginx拜访操控
nginx拜访操控

根据授权的拜访操控

装备进程与Apache根柢一同

  • 生成用户暗码认证文件
  • 修改主装备文件对相应目录,增加认证装备项
  • 重启服务,拜访查验

一,修改主装备文件

[root@localhost ~]# cd /usr/local/nginx/conf     ##切换到装备文件目录
[root@localhost conf]# vim nginx.conf              ##修改Nginx装备文件
location / {
auth_basic "secret";                                ##验证类型
auth_basic_user_file /usr/local/nginx/passwd.db;      ##验证文件途径
root   html;
index  index.html index.htm;
}

二,设备httpd-tools东西包,设置暗码认证文件

[root@localhost conf]# yum install httpd-tools -y    ##设备东西包
[root@localhost conf]# htpasswd -c /usr/local/nginx/passwd.db test    ##设置暗码认证文件
New password:          ##输入暗码
Re-type new password:        ##招认暗码
Adding password for user test
[root@localhost conf]# cat /usr/local/nginx/passwd.db      ##检查暗码认证文件
test:$apr1$LqqHZeX3$24E7/HeacTVRzKA7nvSgY/
[root@localhost conf]# service nginx stop      ##封闭服务
[root@localhost conf]# service nginx start      ##翻开服务

三,运用win10查验机查验

nginx拜访操控
nginx拜访操控

谢谢阅览!!!