源码编译安装Nginx服务及访问控制(实战!)
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,关于Nginx款高性能、轻量级Web服务软件稳定性高系统资源消耗低对HTTP并发连接的处理能力高单台物理服务器可支持30000 ~ 50000个并发请求Nginx编译安装1.宿主机共享所需的工具包2.
千家信息网最后更新 2025年12月02日源码编译安装Nginx服务及访问控制(实战!)
关于Nginx
款高性能、轻量级Web服务软件
稳定性高
系统资源消耗低
对HTTP并发连接的处理能力高
- 单台物理服务器可支持30000 ~ 50000个并发请求
Nginx编译安装
1.宿主机共享所需的工具包

2.虚拟机挂载共享目录
[root@localhost ~]# smbclient -L //192.168.100.50/Enter SAMBA\root's password: OS=[Windows 10 Enterprise LTSC 2019 17763] Server=[Windows 10 Enterprise LTSC 2019 6.3] Sharename Type Comment --------- ---- ------- IPC$ IPC 远程 IPC share Disk tools Disk Users Disk Connection to 192.168.100.50 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)NetBIOS over TCP disabled -- no workgroup available[root@localhost ~]# mkdir /mnt/tools[root@localhost ~]# mount.cifs //192.168.100.50/tools /mnt/tools/Password for root@//192.168.100.50/tools: [root@localhost ~]# cd /mnt/tools/[root@localhost tools]# lsawstats-7.6.tar.gz extundelete-0.2.4.tar.bz2 forbid.png jdk-8u191-windows-x64.zip LAMP-C7 picture.jpgcronolog-1.6.2-14.el7.x86_64.rpm fiddler.exe intellijideahahau2018.rar john-1.8.0.tar.gz LNMP[root@localhost tools]#3.解压Nginx源码包
[root@localhost tools]# cd LNMP/[root@localhost LNMP]# lsDiscuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php-7.1.20.tar.gz[root@localhost LNMP]# tar zxvf nginx-1.12.2.tar.gz -C /opt/.......//省略解压过程4.安装编译Nginx所需环境包
[root@localhost LNMP]# yum -y install gcc gcc-c++ pcre-devel zlib-devel........//省略安装过程[root@localhost LNMP]#5.新建一个程序用户nginx
[root@localhost LNMP]# useradd -M -s /sbin/nologin nginx //-M,不创建家目录[root@localhost LNMP]# id nginx //查看nginx用户uid=1001(nginx) gid=1001(nginx) 组=1001(nginx)[root@localhost LNMP]#6.配置Nginx服务
[root@localhost LNMP]# cd /opt/nginx-1.12.2/[root@localhost nginx-1.12.2]# lsauto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src[root@localhost nginx-1.12.2]# ./configure \> --prefix=/usr/local/nginx \ //安装路径> --user=nginx \ //属主> --group=nginx \ //属组> --with-http_stub_status_module //开启统计模块........//省略配置过程7.编译安装Nginx服务
[root@localhost nginx-1.12.2]# make && make install.........//省略编译过程[root@localhost nginx-1.12.2]# 8.优化nginx命令执行路径
[root@localhost nginx-1.12.2]# cd /usr/local/nginx/[root@localhost nginx]# lsconf html logs sbin[root@localhost nginx]# cd sbin/[root@localhost sbin]# lsnginx[root@localhost sbin]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/[root@localhost sbin]# 9.开启nginx服务
[root@localhost sbin]# nginx -t //检查测试配置文件nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@localhost sbin]# nginx //开启服务[root@localhost sbin]# netstat -ntap | grep 80 //查看80端口tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 52709/nginx: master [root@localhost sbin]#10.关闭防火墙和增强性安全功能
[root@localhost sbin]# systemctl stop firewalld.service //关闭防火墙[root@localhost sbin]# setenforce 0 //关闭增强性安全功能[root@localhost sbin]# 11.安装elinks工具,测试nginx服务
[root@localhost sbin]# yum install elinks -y //安装工具.........//省略安装过程[root@localhost sbin]# [root@localhost sbin]# elinks http://localhost //测试能否访问nginx服务12.用浏览器测试能否访问nginx服务(访问成功)
Nginx服务优化
1.nginx服务基础命令
[root@localhost sbin]# killall -s QUIT nginx //停止服务[root@localhost sbin]# killall -3 nginx //停止服务[root@localhost sbin]# killall -s HUP nginx //重载服务[root@localhost sbin]# killall -1 nginx //重载服务[root@localhost sbin]# nginx //启动服务2.制作管理服务的脚本
[root@localhost sbin]# vim /etc/init.d/nginx#!/bin/bash# chkconfig: - 99 20# description: Nginx Service Control ScriptPROG="/usr/local/nginx/sbin/nginx"PIDF="/usr/local/nginx/logs/nginx.pid"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 1esacexit 0[root@localhost sbin]# chmod +x /etc/init.d/nginx //添加执行权限[root@localhost sbin]# chkconfig --add nginx //添加让系统可以识别[root@localhost sbin]# 3.测试服务管理脚本
[root@localhost sbin]# service nginx stop //停止服务[root@localhost sbin]# netstat -ntap | grep 80 //查看80端口,无[root@localhost sbin]# service nginx start //开启服务[root@localhost sbin]# netstat -ntap | grep 80 //查看80端口,有tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 53614/nginx: master [root@localhost sbin]# 4.修改配置文件,开启统计功能
[root@localhost sbin]# vim /usr/local/nginx/conf/nginx.conf location / { root html; index index.html index.htm; } location /status { stub_status on; access_log off; }[root@localhost sbin]# service nginx stop[root@localhost sbin]# service nginx start [root@localhost sbin]#5.测试统计功能
Nginx服务访问控制
1.修改配置文件,开启密码访问功能
[root@localhost sbin]# vim /usr/local/nginx/conf/nginx.conf location / { auth_basic "secret"; auth_basic_user_file /usr/local/nginx/passwd.db; root html; index index.html index.htm; } location /status { stub_status on; access_log off; }[root@localhost sbin]#2.安装密码访问工具
[root@localhost sbin]# yum install httpd-tools -y........//省略安装过程[root@localhost sbin]# 3.创建访问登录的用户和密码
[root@localhost sbin]# htpasswd -c /usr/local/nginx/passwd.db test New password: Re-type new password: Adding password for user test[root@localhost sbin]# cat /usr/local/nginx/passwd.db test:$apr1$od5a34WH$MduYUJbQ2W0oihB0Bs/bx.[root@localhost sbin]# [root@localhost sbin]# service nginx stop[root@localhost sbin]# service nginx start [root@localhost sbin]# 4.测试访问控制(成功)

服务
测试
过程
功能
配置
编译
工具
密码
文件
用户
端口
统计
控制
安全
成功
命令
目录
系统
脚本
路径
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
河北存储服务器机箱生产云空间
数据库怎么修改上传上限
关于网络安全作文素材大全
查看数据库的pga和sga
嵌入式软件开发太原
收银台连接不了数据库
文件上传服务器状态错误
全军首届军营网络安全宣传周
服务器三个小电视灯一直闪
网络安全协议的理解
国外大学毕业论文数据库
表格中自动填充特定的数据库
市疾控中心网络安全等级保护
思科网络技术学院教程怎么学
极速服务器
服务器掉域后怎么登陆
vue服务器建站管理
网络安全在哪个城市就业前景
桂林抢单软件开发有限公司
盘龙游戏软件开发
数据库表字段重命名
赛摩武汉工业互联网科技有限公司
地下城登录链接服务器失败
网络安全模式如何进入系统
简述移动数据库的关键技术
高峰论坛中国网络安全
古交软件开发哪家便宜
蓝海汇网络技术服务
网络安全管理与信息系统就业
电商系统软件开发服务方案价钱