nginx官网:http://nginx.org

一、apache基金会http 二、微软的IS 三、淘宝基于nginx开发的tengline,阿里(最大的云供应商)在用 四、Google的产品:GWS(Google web server)闭源的外人不可用

OpenEuler网站:https://www.openeuler.openatom.cn/zh/

10-22命令清单:

root@localhost:~# systemctl disable firewalld.service
root@localhost:~# systemctl kill firewalld.serviceroot@localhost:~# setenforce 0
root@localhost:~# systemctl disable httpd   #看到报错
root@localhost:~# systemctl status nginx.service  #看到不是开机自启
CentOS中帮助是-help
不是开机自启的话怎么用:
root@localhost:~# nginx -help
root@localhost:~# rpm -ql nginx   #看nginx的文件在哪里
root@localhost:~# nginx           #启动起来
root@localhost:~# ps -aux | grep nginx   #看nginx的进程
root@www:~# getenforce
root@www:~# setenforce 0

问题:

1.为什么nginx开启后进程是有的,但是nginx服务看着是关的,而且浏览器是能访问的? 答:这个服务进程是开的,服务是好用的,服务查看是关的,是因为没输入systemctl命令去start,systemd只是标记状态,没有扫描我的系统nginx是启动了还是没启动 注意:如果用nginx命令绝对不能用systemctl命令(二选一)

下午

命令:

root@localhost:~# vim /etc/nginx/nginx.conf ![[Pasted image 20261022133832.png]] 非虚拟主机的配置,或者公共配置的话可以定位在 ![[Pasted image 20261022134008.png]] 主配置文件: ![[Pasted image 20261022134548.png]]

写一个配置文件

root@localhost:# ls /etc/nginx/conf.d/ root@localhost:# vim /etc/nginx/conf.d/test.conf

例子:
server {
        server_name www.shida-lab.com;
        root /soft/code/www;
        index index.html;
}

root@localhost:# nginx -t #做语法检查 root@localhost:# mkdir -p /soft/code/www root@localhost:# echo hello world >/soft/code/www/index.html root@localhost:# nginx -s reload #加载 在自己的电脑: 1.记事本–>以管理员身份运行 2.文件:C:\Windows\System32\drivers\etc\hosts 2.加入一条解析

root@localhost:~# curl -v www.shida-lab.com #查看详细信息

server {
        server_name www.shida-lab.com;
        root /soft/code/www;
        index index.html;
        location /mystatus {
                stub_status on;
        }
}

![[Pasted image 20261022142709.png]] 第一行表示当前连接的数量:Reading+Writing+Waiting Reading:正在读客户端的请求 Writing:正在向客户端发送响应的 Waiting:正在等待 第三行对应第二行server后面的三个 server后的accepts和handled通常是相等的,handled表示处理完的请求 requests表示累计处理的请求总数 一个链接上可以有多个请求

server {
        server_name www.shida-lab.com;
        root /soft/code/www;
        index index.html;
        location /mystatus {
                stub_status on;
        }
        location /down {
           root /soft/package/src;
           autoindex on;
           autoindex_localtime on;
           autoindex_exact_size off;
        }
}

写完这些可以在网页上看到文件也可以下载文件 在浏览器输入www.shida-lab.com/down

limit_req_zone $binary_remote_addr zone=req_zone:1m rate=1r/s;
server {
        server_name www.shida-lab.com;
        root /soft/code/www;
        index index.html;
        location / {
            #limit_req zone=req_zone ;
            limit_req zone=one burst=5 nodelay;
        }
        location /mystatus {
                stub_status on;
        }
        location /down {
           root /soft/package/src;
           autoindex on;
           autoindex_localtime on;
           autoindex_exact_size off;
        }
}

root@localhost:# dnf install httpd-tools -y #压测工具 root@localhost:# ab -n 50 -c 20 http://172.24.126.140/index.html #压测 限制之后超多少扔多少,nodelay表示不用等待直接处理 $binary_remote_addr:二进制数远程地址。

root@localhost:~# vim /etc/nginx/conf.d/test.conf

server {
        server_name www.shida-lab.com;
        root /soft/code/www;
        index index.html;
        location ~^/1.html {
                root /soft/code;
                index index.html;
                deny 172.24.126.140;
                allow all;
        }
    }

root@localhost:~# vim /soft/code/1.html

<h1>deny 172.24.126.140 allow all</h1>

root@localhost:~# curl www.shida-lab.com/1.html #网页可以访问,命令行不可以

1.~ 区分大小写的正则表达式 * 不区分大小写 2.^/1.html 只能匹配以/1.html开始的url 3.^/1.html /1.HTML

root@localhost:~# vim /etc/nginx/conf.d/test.conf #弄一个登录界面

location /down {
           root /soft/package/src;
           autoindex on;
           autoindex_localtime on;
           autoindex_exact_size off;
           auth_basic "Download please username and password";
           auth_basic_user_file /etc/nginx/auth_conf;

root@localhost:# htpasswd -c /etc/nginx/auth_conf user1 root@localhost:# cat /etc/nginx/auth_conf ![[Pasted image 20261022161347.png|184]] 如果想要新加一个用户: root@localhost:# htpasswd -b /etc/nginx/auth_conf user2 redhat123 root@localhost:# cat /etc/nginx/auth_conf 局限性: 1.用户信息依赖文件方式 2.用户管理文件过多,无法联动 3.全都是操作机械的,效率很低 4.解决方法:nginx结合LUA实现高效认证

基于不同域名的访问

root@www:/etc/nginx/conf.d# vim test.conf

#limit_req_zone $binary_remote_addr zone=req_zone:1m rate=1r/s;
#limit_conn_zone $binary_remote_addr zone=conn_zone:10m;
server {
        server_name www.shida-lab.com;
        root /soft/code/www;
        index index.html;
}

server {
        server_name www.shida-blog.com;
        root /soft/code/blog;
        index index.html;
}

root@www:# mkdir /soft/code/blog root@www:# echo “hello www” >/soft/code/www/index.html root@www:# echo “hello blog” >/soft/code/blog/index.html root@www:# vim /etc/hosts #写完网页要写解析 ![[Pasted image 20261023095026.png]] root@www:# nginx -t root@www:# nginx -s reload

为什么用80端口? 因为nginx主配置文件内默认监听的是80都那口

root@www:/etc/nginx/conf.d# vimdiff test.conf test1.conf #比对两个文件 如果两个文件域名是一样的,会按照文件名的ASCII排序,先加载的生效

server {
        listen 8001;
        server_name www.shida-lab.com;
        root /soft/code/www;
        index index.html;
}

server {
        listen 8002
        server_name www.shida-lab.com;
        root /soft/code/blog;
        index index.html;
}
改成不同端口
在网页搜www.shida-lab.com:8001或者www.shida-lab.com:8002
server{
        listen 80;
        server_name www.shida-lab.com shida-lab.com;
        root /soft/code/www;
        index index.html;
}

server {
        listen 8002;
        server_name www.shida-lab.com;
        root /soft/code/blog;
        index index.html;
}