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具有诸多优点,但在实际应用中仍需根据具体需求和环境进行配置和优化

相关内容

热门资讯

黑科技苹果版(云扑克辅助挂)外... 黑科技苹果版(云扑克辅助挂)外挂透明挂辅助工具(透视)新版2025教程(2021已更新)(哔哩哔哩)...
黑科技规律!wepoke有挂吗... 黑科技规律!wepoke有挂吗蓝鸟,太夸张了竟然是有挂(透视)AA德州教程(2020已更新)(哔哩哔...
黑科技设备(wePOke)外挂... 黑科技设备(wePOke)外挂透明挂黑科技辅助插件(透视)详细教程(2024已更新)(哔哩哔哩)1、...
黑科技教程(微扑克机器人)外挂... 黑科技教程(微扑克机器人)外挂透明挂辅助黑科技(透视)透明教程(2026已更新)(哔哩哔哩);1、微...
黑科技能赢!we辅助poker... 黑科技能赢!we辅助poker德之星,太离谱了一贯是有挂(透视)高科技教程(2020已更新)(哔哩哔...
黑科技透明挂(鱼扑克)外挂透明... 黑科技透明挂(鱼扑克)外挂透明挂黑科技辅助器(透视)AI教程(2020已更新)(哔哩哔哩);黑科技透...
黑科技有挂(aapoker手游... 黑科技有挂(aapoker手游版)外挂透明挂辅助黑科技(透视)大神讲解(2020已更新)(哔哩哔哩)...
黑科技ai!德州之星辅助器有哪... 黑科技ai!德州之星辅助器有哪些功能,太无语了果然真的有挂(透视)2025新版教程(2020已更新)...
黑科技最新(cloudpoke... 黑科技最新(cloudpoker云扑克)外挂透明挂黑科技辅助软件(透视)解密教程(2021已更新)(...
黑科技ai代打(德扑操作)外挂... 黑科技ai代打(德扑操作)外挂透明挂辅助挂(透视)实用技巧(2020已更新)(哔哩哔哩)1)德扑操作...