今日内容

  • 上一篇测试
  • c出现问题
  • web 服务
  • 部署 Nginx

内容详细

上一篇测试

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

出现的问题

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

web 服务

1、web 服务简介

2、网络模型

网络模型
select
poll
epoll

3、web 服务器软件

1、apache

2、Nginx

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

部署 Nginx

1、安装

1、yum 安装

登录 Nginx 官网 nginx.org
选择 download --> 稳定版本下载 [root@web01 ~]# vim /etc/yum.repos.d/nginx.repo
[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

2、平滑增加 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

3、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;'

4、Nginx 配置文件

存放目录

	/etc/nginx/nginx.conf

配置分为 全局配置 和 模块配置

1、全局配置

1、user : 指定 Nginx 启动用户
2、worker_processes : 定义 Nginx 的 worker 进程数
auto == CPU数量
3、error_log : 错误日志路径
4、pid : pid 的存放文件路径
user  nginx;
worker_processes auto; error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;

2、模块配置

# events : 模块配置

1、events : 模块配置
1.1、worker_connections :每一个worker进程最多同时接入多少个请求
2.2、use : 指定Nginx的网络模型(select、poll、epoll) 2、http : web服务的模块
2.1、include : 加载外部的配置项(可以降低当前配置文件的复杂度)
2.2、default_type : 如果找不到文件的类型,则按照指定默认类型处理
2.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 ;
2.4、sendfile : 高效读取文件
2.5、keepalive_timeout : 长连接保持连接的
HTTP 1.0 短链接
HTTP 1.1 长连接
2.6、server : 网址模块
2.6.1、listen : 监听的端口
2.6.2、server_name : 定义域名
2.6.3、location : 访问路径( '/' 表示访问任何地址都会到这里)
6.6.3.1、root : 指定网址路径
6.6.3.2、index : 指定网址的索引文件
http {
include /etc/nginx/mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
#tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf;
}
# server 模块
目录 : /etc/nginx/conf.d/default.conf
作用 : 指定输入相应域名时 'server_name localhost;'
会进入对应的(访问路径)网页目录 和 首页
'root /usr/share/nginx/html;
index index.html index.htm;' server {
listen 80;
server_name localhost; #access_log /var/log/nginx/host.access.log main; location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

5、搭建游戏网站

超级玛丽

1、创建访问目录

	mkdir /opt/super_Maro

[root@web01 opt]# mkdir super_Maro

2、上传游戏原代码

xftp 上传

lrzsz 拖拽

3、编辑网站的配置文件( *.conf )

网站的配置文件创建在 /etc/nginx/conf.d/ 目录下
配置文件命名 : *.conf [root@web01 conf.d]# vim /etc/nginx/conf.d/game.conf
server {
listen 80;
server_name game.maro.com;
location / {
root /opt/super_Maro;
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.maro.com

注意

如果修改了 域名解析文件 hosts 还是用不了 该域名访问相应网址
应该时 Notepad++ 没有权限保存修改结果,给予权限多保存几次就可以了

附录(nginx 配置文件)

/etc/nginx/nginx.conf
[root@web01 nginx]# cat nginx.conf user nginx;
worker_processes auto; error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid; events {
worker_connections 1024;
} http {
include /etc/nginx/mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
#tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf;
}

搭建 Nginx 服务的更多相关文章

  1. 搭建Nginx服务

    Nginx 是一个高性能的 http 和反向代理服务器,也是一个 IMAP/POP3/SMPT 服务器. Nginx 是由 logor Sysoev 为俄罗斯访问第二的 Ranbler.ru 站点开发 ...

  2. Linux之Nginx服务 nfs文件存储 负载均衡

    一.搭建Nginx服务 Nginx 是俄罗斯人编写的十分轻量级的HTTP 服务器,Nginx,它的发音为"engine X",是一个高性能的HTTP和反向代理服务器,同时也是一个I ...

  3. nginx服务傻瓜搭建

    nginx服务傻瓜搭建 安装步骤: 一.先准备好相关源码包和程序包,如下图 所有包都在云服务器的/src目录下. 二.安装 1.安装nginx服务器,支持vod stream.fileupload c ...

  4. pm2命令,端口查询,mongodb服务启动,nginx服务启动,n模块的使用,搭建nodejs服务器环境,搭建oracledb服务器环境 linux的环境搭建

    pm2命令 pm2 ls //查询pm2 启动的列表 pm2 start app.js //启动文件 pm2 restart app //重启项目 pm2 logs app //监控项目执行日志打印 ...

  5. python3.x +django + nginx + uwsgi 搭建web服务

    最近一直在用django开发自己的网站.在开发和线上环境的对接过程中遇到了许多的坑.所以想以一个老鸟的经历来写一下怎么 搭建web服务 一.python3.x .django .nginx .uwsg ...

  6. 三、直播整体流程 五、搭建Nginx+Rtmp直播流服务

    HTML5实现视频直播功能思路详解_html5教程技巧_脚本之家 https://m.jb51.net/html5/587215.html 三.直播整体流程 直播整体流程大致可分为: 视频采集端:可以 ...

  7. ubuntu 搭建Mercurial 服务(nginx)

    ubuntu 搭建Mercurial 服务(nginx) 环境:ubuntu 12.05  Mercurial 步骤: (1)安装nginx 和 Mercurial: sudo apt-get ins ...

  8. Nginx学习之配置RTMP模块搭建推流服务

    写在开始 小程序升级实时音视频录制及播放能力,开放 Wi-Fi.NFC(HCE) 等硬件连接功能.同时提供按需加载.自定义组件和更多访问层级等新特性,增强了第三方平台的能力,以满足日趋丰富的业务需求. ...

  9. Linux服务-搭建Nginx

    任务目标:二进制安装nginx包,作为web服务修改配置文件,让配置生效,验证配置 首先使用yum 来安装 nginx 服务,基于epel-release平台的nginx需要epel的支持,所以要先安 ...

随机推荐

  1. vue - public 引入 <script>报错 Uncaught SyntaxError: Unexpected token '<'

    1.现象 原本我是直接在母版引入 <script type="application/javascript" src="static/config.js" ...

  2. 安装与配置文本编辑器vim

    1.安装 查看是否已经安装vim,在命令行敲入"vi"后按"tab"键,如果只看到有默认的vi和vim.tiny,则为未安装,vim.tiny是vim的精简版 ...

  3. CentOS 7 使用unzip解压zip文件提示未找到命令的解决方法

    故障现象: 解决方法: 如果你使用unzip命令解压.zip文件,提示未找到命令,可能是你没有安装unzip软件,下面是安装方法 [root@localhost www]# yum install - ...

  4. react中使用antd按需加载(第一部)

    什么是react按需加载?简单来说就是当我们引用antd的时候需要引入全局css样式,这会对性能造成一定的影响,那么使用按需加载以后就不需要引入css全局样式了,直接引入功能模块即可,既然需要设置按需 ...

  5. 第10组-Alpha冲刺 总结

    1.基本情况 组长博客链接:https://www.cnblogs.com/cpandbb/p/14007413.html 答辩总结: ·产品偏离了最开始的方向,地图和刷一刷功能做得没那么好,外卖订单 ...

  6. PPT制作手机手指滑动效果

    原文链接:https://www.toutiao.com/i6495304998786695694/ 上一节我们完成了手机滑动粗糙效果,这部分我们将给动画添加一个手指的图片. 首先,选择"插 ...

  7. STC8H开发(四): FwLib_STC8 封装库的介绍和注意事项

    目录 STC8H开发(一): 在Keil5中配置和使用FwLib_STC8封装库(图文详解) STC8H开发(二): 在Linux VSCode中配置和使用FwLib_STC8封装库(图文详解) ST ...

  8. dart系列之:和null说再见,null使用最佳实践

    目录 简介 不需要初始化对象为null null的三元操作符 如果在使用中需要判断类型是否为空,则不要使用late 本地变量的类型提升 总结 简介 null可能是大家在编写程序中最为头疼的一个东西,稍 ...

  9. 理解ASP.NET Core - 基于Cookie的身份认证(Authentication)

    注:本文隶属于<理解ASP.NET Core>系列文章,请查看置顶博客或点击此处查看全文目录 概述 通常,身份认证(Authentication)和授权(Authorization)都会放 ...

  10. leetcode 1021. 删除最外层的括号

    问题描述 有效括号字符串为空 ("")."(" + A + ")" 或 A + B,其中 A 和 B 都是有效的括号字符串,+ 代表字符串的 ...