稳定性高
系统资源消耗低
对HTTP并发链接的处理能力高php
- 单台物理服务器可支持30000~50000个并发请求
一台Linux服务器(192.168.13.128) 一台win10测试机
[root@localhost ~]# smbclient -L //192.168.100.3/ ##远程共享访问 Enter SAMBA\root's password: Sharename Type Comment --------- ---- ------- LAMP-C7 Disk [root@localhost ~]# mount.cifs //192.168.100.3/LAMP-C7 /mnt ##挂载到/mnt目录下
[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
[root@localhost opt]# yum -y install \ gcc \ //c语言 gcc-c++ \ //c++语言 pcre-devel \ //pcre语言工具 zlib-devel //数据压缩用的函式库
[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 ##状态统计模块
[root@localhost nginx-1.12.0]# make ##编译 ... [root@localhost nginx-1.12.0]# make install ##安装 ...
[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
[root@localhost nginx]# yum install elinks -y ##安装elinks软件 [root@localhost nginx]# elinks http://localhost ##测试nginx网页
[root@localhost nginx]# killall -s QUIT nginx ##中止 或者使用killall -3 nginx [root@localhost nginx]# killall -s HUP nginx ##重启 或者使用killall -1 nginx [root@localhost nginx]# nginx ##开启
[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
- 启用HTTP_STUB_STATUS状态统计模块
- nginx -V能够查看已安装的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; }
[root@localhost conf]# yum install bind -y ##安装DNS服务
[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; }; ##容许全部
[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; }; };
[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 添加域名解析地址为本机
[root@localhost named]# systemctl start named ##开启dns服务 [root@localhost named]# systemctl stop firewalld.service ##关闭防火墙 [root@localhost named]# setenforce 0 ##关闭加强功能
- 生成用户密码认证文件
- 修改主配置文件对相应目录,添加认证配置项
- 重启服务,访问测试
[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; }
[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 ##开启服务