ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

nginx

2022-01-01 15:35:24  阅读:147  来源: 互联网

标签:http 配置文件 etc backup nginx root


??

1、NFS共享文件步骤

- 服务端

[root@backup ~]# yum install nfs-utils rpcbind -y
[root@backup ~]# mkdir /backup
[root@backup ~]# vim /etc/exports
/backup 172.16.1.0/20(rw,sync,all_squash,anonuid=666,anongid=666)
[root@backup ~]# groupadd www -g 666
[root@backup ~]# useradd www -u 666 -g 666 -M -r -s /sbin/nologin
[root@backup ~]# chown -R www.www /backup
[root@backup ~]# systemctl start nfs-server rpcbind


- 客户端
[root@backup ~]# yum install nfs-utils -y
[root@backup ~]# mount -t nfs 172.16.1.31:/backup /opt

2、安装WEb服务的步骤
[root@backup ~]# yum install httpd php php-devel -y
[root@backup ~]# cd /var/www/html

2、昨日问题

1、nfsnobody
2、NFS挂载无法持久化
	1、通过开机自启动脚本挂载
		[root@web01 html]# vim /etc/rc.local
		/usr/bin/mount -t nfs 172.16.1.31:/web/upload /var/www/html/upload
		[root@web01 html]# chmod +x /etc/rc.d/rc.local 

	2、通过/etc/fstab配置文件
		[root@web02 ~]# vim /etc/fstab
		# 挂载点                  挂载的目录            类型   设置默认权限    0 不备份 1 备份     0 不检查 1 检查
172.16.1.31:/web/upload  /var/www/html/upload   nfs       defaults          0                0
		[root@web02 ~]# mount -a

3、今日内容

1、了解web服务
2、部署Nginx
	Nginx和Apache的对比

4、什么是web服务

web就是B/S架构

5、web服务器软件

1、apache
网络模型
	select
	poll
	epoll

2、Nginx

官网:https://nginx.org/
软件:https://nginx.org/download/

部署nginx

yum安装

1.到官网下载配置文件
image
image
image
image
image
image
2.编辑创建文件

vim /etc/yum.repos.d/nginx.repo

image
3.编辑内容

[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

image

4.下载nginx

yum install nginx -y

image
5.启动nginx

systemctl start nginx

image

编译安装

1.下载安装包
image
image

上述鼠标右键复制链接地址

wget https://nginx.org/download/nginx-1.20.2.tar.gz

image
2.解压压缩包

tar -xf nginx-1.20.2.tar.gz

image
3.cd进入nginx-1.20.2

cd nginx-1.20.2

image
4.在当前目录运行configure

./configure

image
5.make

make

6.make install

nake install

平滑增加nginx模块

编译安装的nginx没有任何模块,需要添加。
添加时可以重新编译

1.编辑配置文件
2.解压
3.cd到nginx中
4.运行

./configure  --with-http_ssl_module

--with-http_ssl_module
添加的模块
image
make
make install
注:编译安装的nginx需要到/usr/local/nginx/sbin/nginx -v
才可以查询如版本号,因为编译安装没有架构nginx添加进入环境变量
添加环境变量

export PATH=$PATH:/usr/local/nginx/sbin

nginx命令

1、-v : 打印版本号
	[root@web01 ~]# nginx -v
	nginx version: nginx/1.20.2

2、-V : 打印版本号和配置项
	[root@web01 ~]# nginx -V
	nginx version: nginx/1.20.2
	built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
	built with OpenSSL 1.0.2k-fips  26 Jan 2017
	TLS SNI support enabled
	configure arguments: --prefix=/etc/nginx 

3、-t : 检查配置文件
	[root@web01 ~]# nginx -t
	nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
	nginx: configuration file /etc/nginx/nginx.conf test is successful

4、-T : 测试配置文件并启动

5、-q :打印错误日志

6、-s : 操作进程
		stop	:停止
		quit	:退出
		reopen	:重启
		reload	:重载
7、-p : 指定nginx的工作目录
8、-e : 指定错误日志路径
9、-c : 指定配置文件的路径
10、-g : 设置一个全局的Nginx配置项
[root@web01 ~]# nginx -g 'daemon off;'

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、use : 指定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 ;
    	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 : 指定网址的索引文件

测试

1、上传代码

2、编辑配置文件
[root@web01 conf.d]# vim /etc/nginx/conf.d/game.conf 
server {
    listen 80;
    server_name game.test.com;
    location / {
        root /opt/Super_Marie;
        index index.html;
    }
}

3、测试配置文件是否正常
[root@web01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

4、重启Nginx
[root@web01 conf.d]# systemctl restart nginx 

5、域名解析
C:\Windows\System32\drivers\etc\hosts
172.16.1.7 game.test.com

标签:http,配置文件,etc,backup,nginx,root
来源: https://www.cnblogs.com/yuanyangguo/p/15755463.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有