架构(day10)

网友投稿 227 2022-10-31


架构(day10)

Web基础入门

Nginx概述

Nginx是一个开源且高性能、可靠的Http Web服务、代理服务。

开源: 直接获取源代码高性能: 支持海量并发可靠: 服务稳定

Nginx应用场景

nginx快速安装

rpm安装(yum安装)

epel仓库(阿里云)官方仓库

源码安装

使用官方源

Nginx官方网站:​​TP​​

# 1.添加nginx官方源 [root@web01 ~]# vim /etc/yum.repos.d/nginx.repo [nginx-stable] name=nginx stable repo baseurl=gpgcheck=1 enabled=1 gpgkey=module_hotfixes=true # 2.安装nginx [root@web01 ~]# yum install -y nginx # 3.启动nginx并加入开机自启 [root@web01 ~]# systemctl start nginx [root@web01 ~]# systemctl enable nginx # 4.查看nginx的版本 [root@web01 ~]# nginx -v nginx version: nginx/1.22.0 # 5.查看nginx的版本和源码安装生成步骤的参数有哪些 [root@web01 ~]# nginx -V --prefix=/application/nginx-1.22.0 --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with---with---with---with---with---with---with---with---with---with---with---with---with---with---with---with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,- D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 - grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now - pie'

nginx的启停

# 1.启动 systemctl start nginx nginx /app/nginx/sbin/nginx # 2.停止 systemctl stop nginx nginx -s stop /app/nginx/sbin/nginx -s stop # 3.重新加载 systemctl reload nginx nginx -s reload /app/nginx/sbin/nginx -s reload -c:指定配置文件的路径 -t:检查配置文件的语法(无法检测单词拼写) -s:启停重载,服务操作 -v:查看版本号 -V:查看版本和编译参数 ## nginx启动脚本systemd管理 [root@web01 ~]# vim /usr/lib/systemd/system/nginx.service [Unit] Description=nginx - high performance web server Documentation=After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)" ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)" [Install] WantedBy=multi-user.target ## 源码安装,使用fpm打包,脚本内容: # 先写脚本 [root@web01 ~]# vim post_install_nginx.sh ln -s /application/nginx-1.20.2 /opt/nginx echo 'PATH="/usr/local/nginx/sbin:$PATH"' > /etc/profile.d/nginx.sh cat >> /usr/lib/systemd/system/nginx.service <

nginx配置文件

1.Nginx主配置文件

路径

类型

作用

/etc/nginx/nginx.conf

配置文件

nginx主配置文件

/etc/nginx/conf.d/default.conf

配置文件

nginx网站示例配置文件

2.Nginx代理相关参数文件

路径

类型

作用

/etc/nginx/fastcgi_params

配置文件

Fastcgi代理配置文件

/etc/nginx/scgi_params

配置文件

scgi代理配置文件

/etc/nginx/uwsgi_params

配置文件

uwsgi代理配置文件

3.Nginx编码相关配置文件

路径

类型

作用

/etc/nginx/win-utf

配置文件

Nginx编码转换映射文件

/etc/nginx/koi-utf

配置文件

Nginx编码转换映射文件

/etc/nginx/koi-win

配置文件

Nginx编码转换映射文件

/etc/nginx/mime.types

配置文件

Content-Type与扩展名

4.Nginx管理相关命令

路径

类型

作用

/usr/sbin/nginx

命令

Nginx命令行管理终端工具

/usr/sbin/nginx-debug

命令

Nginx命令行与终端调试工具

5.Nginx日志相关目录与文件

路径

类型

作用

/var/log/nginx

目录

Nginx默认存放日志目录

/etc/logrotate.d/nginx

配置文件

Nginx默认的日志切割

nginx配置文件详解

多虚拟主机(多web网站配置)

在企业中,是不可能用一个nginx对应一套业务,多个网站都在一个nginx中配置

基于IP的多虚拟主机

[root@web01 conf.d]# ifconfig eth0:0 10.0.0.10 [root@web01 conf.d]# ifconfig eth0:1 10.0.0.11 [root@web01 conf.d]# cat 1_game.conf server{ listen 80; server_name 10.0.0.10; location /{ root /game/h5_games; index index.html; } } [root@web01 conf.d]# cat 1_wjh.conf server{ listen 80; server_name 10.0.0.7; root /code; location /{ index index.html; } location /wjh{ index index_1.html huanglong.html; } } [root@web01 conf.d]# ifconfig eth0: flags=4163 mtu 1500 inet 10.0.0.7 netmask 255.255.255.0 broadcast 10.0.0.255 inet6 fe80::a319:8c13:9238:5bb6 prefixlen 64 scopeid 0x20 inet6 fe80::3077:9382:f10c:ae23 prefixlen 64 scopeid 0x20 ether 00:0c:29:9a:b0:68 txqueuelen 1000 (Ethernet) RX packets 80416 bytes 76841088 (73.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 47140 bytes 15283547 (14.5 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth0:0: flags=4163 mtu 1500 inet 10.0.0.10 netmask 255.0.0.0 broadcast 10.255.255.255 ether 00:0c:29:9a:b0:68 txqueuelen 1000 (Ethernet)

基于多端口的虚拟主机

[root@web01 conf.d]# cat game.conf server{ listen 8081; server_name 10.0.0.7; location /{ root /game/h5_games; index index.html; } } [root@web01 conf.d]# cat wjh.conf server{ listen 8082; server_name 10.0.0.7; root /code; location /{ index index.html; } location /wjh{ index index_1.html huanglong.html; } }

基于多域名的虚拟主机

[root@web01 conf.d]# cat blog.wjh.com.conf server{ listen 80; server_name blog.wjh.com; root /wjh1; index index.html; } [root@web01 conf.d]# cat wjh.com.conf server{ listen 80; server_name wjh.com; root /wjh; index index.html; }

在windows系统中,配置本地的DNS

1.按win+r打开运行

2.输入:drivers

3.进入与etc目录

4.使用notepad++打开hosts文件

5.添加域名解析


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:自动化接口测试(自动化接口测试脚本)
下一篇:接口在线测试(接口测试)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~