源码编译安装Nginx服务及访问控制(实战!)
发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,关于Nginx款高性能、轻量级Web服务软件稳定性高系统资源消耗低对HTTP并发连接的处理能力高单台物理服务器可支持30000 ~ 50000个并发请求Nginx编译安装1.宿主机共享所需的工具包2.
千家信息网最后更新 2025年02月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安全错误
数据库的锁怎样保障安全
数据库原理及技术钱雪忠
和平精英的服务器账号怎么找
智能软件开发培训
怎么有个安全的服务器
哪家学软件开发好
哪里有学网络技术
数据库中表格怎么复制粘贴
ns 2k19服务器关闭了吗
网络安全管理的重要
浙江交友软件开发价格表
本地电脑安装数据库服务
数据库导出问题怎么解决
六年级网络安全征文500
数字货币互联网科技
免费手机数据库软件免费下载
普陀区参考数据库销售厂家报价
软件开发培训学校阴
flask 数据库界面
计算机软件开发的利润一般
软件开发公司人员比例
软件开发学徒工资多少
基于区块链的网络安全
数据库转移赚钱吗
上海多知互联网科技公司怎么样
网络技术达不到工程师级别
复高软件开发有限公司招聘
网络安全的未来在云端
海南租赁管理软件开发公司
六年级网络安全征文500
江宁租房软件开发