Nginx网站服务
创始人
2025-01-09 03:33:36
0

关于Nginx

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

                稳定性高

                系统资源消耗低

                对http并发连接的处理能力高

                对单台物理服务器可支持30000~50000个并发请求

代码操作

        基于账号密码

yum -y install pcre-devel zlib-devel gcc++ gcc        #下载一些配置文件 [root@bogon ~]# useradd -M -s /sbin/nologin nginx        #创建nginx用户-M是文件不被创建或复制 [root@bogon ~]# ls        #上传软件包 anaconda-ks.cfg  nginx-1.12.0.tar.gz  test.sh [root@bogon ~]# tar zxf nginx-1.12.0.tar.gz  -C /usr/src/        #解包 [root@bogon ~]# cd /usr/src/nginx-1.12.0/        #切换到这个目录 [root@bogon nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module        #编译安装nginx Web服务器 [root@bogon nginx-1.12.0]# make &&make install           #编译和安装Nginx  [root@bogon nginx-1.12.0]# ls /usr/local/nginx/     conf  html  logs  sbin [root@bogon nginx-1.12.0]# /usr/local/nginx/sbin/nginx         #启动nginx [root@bogon nginx-1.12.0]# ss -nlpt |grep 80            #查询80端口有没有nginx [root@bogon nginx-1.12.0]# curl http://192.168.93.131        #访问nginx [root@bogon nginx-1.12.0]# /usr/local/nginx/sbin/nginx -s stop        #停止nginx [root@bogon nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/        #设置软连接 [root@bogon nginx-1.12.0]# vi /etc/init.d/nginx        #写一个脚本 #!/bin/bash # 必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10 # 90是启动优先级,10是停止优先级,优先级范围是0-100,数字越大,优先级越低 #chkconfig: 2345 10 90 #description:Nginx Service Control Script PROG="/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 1 esac exit 0 chmod +x /etc/init.d/nginx            #给脚本一个运行权限  chkconfig --add nginx                #将nginx添加到服务列表中  systemctl status nginx                #关闭nginx [root@bogon ~]# vi /usr/local/nginx/conf/nginx.conf        #nginx基础配置文件 在里面47行左右添加 location /status {              stub_status on;          } [root@bogon ~]# systemctl start nginx        #启动nginx 然后去浏览器验证nginx是否成功    192.168.93.131/status  yum install -y httpd-tools htpasswd -c /usr/local/nginx/passwd.db test 输入密码123456 再次输入密码123456 [root@bogon ~]# chmod 400 /usr/local/nginx/passwd.db [root@bogon ~]# chown nginx /usr/local/nginx/passwd.db [root@bogon ~]# ll -d /usr/local/nginx/passwd.db [root@bogon ~]# vi /usr/local/nginx/conf/nginx.conf        #打开nginx配置文件     #在47行左右的/status下面添加     auth_basic "secret";   # 添加认证          auth_basic_user_file /usr/local/nginx/passwd.db; # 指定认证的账户密码文件 [root@bogon ~]# systemctl restart nginx
基于客户端
[root@bogon ~]# vi /usr/local/nginx/conf/nginx.conf         #在status下面添加删除上次添加的两行            deny 192.168.93.131;         allow all; [root@bogon ~]# systemctl restart nginx [root@bogon ~]# curl http://192.168.93.131/status
虚拟主机
[root@bogon ~]# vi /usr/local/nginx/conf/nginx.conf 在#gzip on;下面添加     server {         listen    80;         server_name www.kgc01.com;         location /{                 root html/kgc01;                 index index.html index.htm;                 }         }     server {         listen    80;         server_name www.kgc02.com;         location /{                 root html/kgc02;                 index index.html index.htm;                 }         } [root@bogon ~]# mkdir /usr/local/nginx/html/kgc01 [root@bogon ~]# mkdir /usr/local/nginx/html/kgc02 [root@bogon ~]# echo 'This is kgc01' > /usr/local/nginx/html/kgc01/index.html [root@bogon ~]# echo 'This is kgc02' > /usr/local/nginx/html/kgc02/index.html [root@bogon ~]# systemctl restart nginx [root@bogon ~]# vi /etc/hosts 192.168.93.131 www.kgc01.com 192.168.93.131 www.kgc02.com [root@bogon ~]# curl www.kgc01.com This is kgc01 [root@bogon ~]# curl www.kgc02.com This is kgc02
基于端口
[root@bogon ~]# vi /usr/local/nginx/conf/nginx.conf 在#gzip on;下面添加     server {         listen    192.168.93.131:81;         server_name 192.168.93.131:81;         location /{                 root html/kgc01;                 index index.html index.htm;                 }         }     server {         listen    192.168.93.131:82;         server_name 192.168.93.131:82;         location /{                 root html/kgc02;                 index index.html index.htm;                 }         } nginx -t systemctl restart nginx

Nginx具有诸多优点,但在实际应用中仍需根据具体需求和环境进行配置和优化

相关内容

热门资讯

据玩家消息!poker wor... 据玩家消息!poker world辅助(透视)本来是有辅助下载(有挂工具)-哔哩哔哩1)poker ...
外挂教程书!约局吧开挂神器是真... 外挂教程书!约局吧开挂神器是真的吗,哈糖大菠萝有挂吗-本来是有辅助脚本(哔哩哔哩)亲,关键说明,约局...
揭秘关于!wepoker透视脚... 揭秘关于!wepoker透视脚本网页,新樱花互娱源码,好像存在有辅助下载(有挂教程)1、实时新樱花互...
外挂手段!pokermaste... 外挂手段!pokermaster修改器,竞技联盟透视-竟然真的有辅助工具(哔哩哔哩)1)pokerm...
透视工具!hhpoker辅助挂... 透视工具!hhpoker辅助挂是真的吗(透视)一直真的有辅助平台(有挂教学)-哔哩哔哩1、透视工具!...
今日头条!红龙poker辅助器... 今日头条!红龙poker辅助器免费观看,财神十三章张助安装包,都是是有辅助神器(有挂教程)1)红龙p...
外挂方案!拱趴游戏破解器,so... 外挂方案!拱趴游戏破解器,sohoo poker辅助器-好像有辅助技巧(哔哩哔哩)1、拱趴游戏破解器...
有了最新消息!wepoker脚... 有了最新消息!wepoker脚本(透视)果然是有辅助平台(有挂方针)-哔哩哔哩1)wepoker脚本...
玩家必看科普!wpk德州局怎么... 玩家必看科普!wpk德州局怎么透视,天天手游辅助工具,切实真的有辅助脚本(存在有挂)暗藏猫腻,小编详...
外挂阶段!werplan怎么作... 外挂阶段!werplan怎么作必弊,hardrock透视工具-好像一直总是有辅助工具(哔哩哔哩)we...