部署nginx

image

web

什么是web

web就是B/S架构

web服务器软件

1、apache
网络模型:select poll epoll
2、nginx
官网:https://nginx.org/
软件:https://nginx.org/download/

部署nginx

1、yum安装
1、yum安装
[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo -->将以下内容写进nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[root@web01 ~]# yum install nginx -y
[root@web01 ~]# systemctl stop httpd
[root@web01 ~]# systemctl start nginx

2、二进制安装
3、编译安装
[root@web01 ~]# wget https://nginx.org/download/nginx-1.20.2.tar.gz
[root@web01 ~]# tar -xf nginx-1.20.2.tar.gz
[root@web01 nginx-1.20.2]# ./configure
[root@web01 nginx-1.20.2]# make
[root@web01 nginx-1.20.2]# make install
4、平滑增加nginx模块
⚠️增加模块必须重新编译
[root@web01 ~]# tar -xf nginx-1.20.2.tar.gz
[root@web01 ~]# cd nginx-1.20.2
[root@web01 nginx-1.20.2]#./configure --with-http_ssl_module
[root@web01 nginx-1.20.2]#make
[root@web01 nginx-1.20.2]#make install

nginx命令

-v :打印版本号
-V:打印版本号和配置项
-t:检查配置文件是否正确
-T:测试配置文件并且启动
-q:打印错误日志
-s:操作进程
	stop-->停止
	quit-->退出
	reopen-->重启
	reload-->重载
-p:指定nginx的工作目录
-e:指定错误日志的路径
-c:指定配置文件的路径
-g:设置一个全局的nginx配置项

#nginx配置项

全局配置
1、user :指定nginx的启动用户
2、worker_processes :定义nginx的worker进程数
auto=cpu数量
3、error_log :错误日志路径
4、pid :pid的存放文件路径
5、events :模块配置
5.1 worker_connections 每一个worker进程最多同时接入多少个请求
5.2 user 指定nginx的网络模型
6、http :web服务的模块
	6.1 include 加载外部的配置项
	6.2 default_type 如果找不到文件类型,则按照指定默认类型处理
	6.3 log_format :定义日志格式 

例如:

log_format json '{"@timestamp":"$time_iso8601",'
				  '"host":"$server_addr",'
				  '"service":"nginxTest",'
				  '"trace":"$upstream_http_ctx_transaction_id",'
				  '"log":"log",'
				  '"clientip":"$remote_addr",'
				  '"remote_user":"$remote_user",'
				  '"request":"$request",'
				  '"http_user_agent":"$http_user_agent",'
				  '"size":$body_bytes_sent,'
				  '"responsetime":$request_time,'
				  '"upstreamtime":"$upstream_response_time",'
				  '"upstreamhost":"$upstream_addr",'
				  '"http_host":"$host",'
				  '"url":"$uri",'
				  '"domain":"$host",'
				  '"xff":"$http_x_forwarded_for",'
				  '"referer":"$http_referer",'
				  '"status":"$status"}';
access_log /var/log/nginx/access.log json ;
⚠️:log_format可以用两个只要后面跟上不同的名字就行


6.4 sendfile :高效读取文件
6.5 keepalive_timeout :长链接保持连接的时间
HTTP 1.0 短链接
HTTP 1.1 长链接
6.6 server :网址模块
	6.6.1 listen 监听的端口
	6.6.2 server_name 定义域名
	6.6.3 location 访问路径
		6.6.3.1 root 指定网址路径(网站跟目录)
		6.6.3.2 index :指定网址的索引文件 --> index:index.html

小游戏搭建

1、在/opt下创建文件夹superM,然后将代码上传
image
2、编辑配置文件 vim /etc/nginx/conf.d/game.conf
image
3、测试配置文件是否正常 nginx -t
4、重启nginx
5、域名解析
192.168.15.9 game.test.com

posted @   JudyJU  阅读(35)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示