框架5--nginx安装部署(web服务)

1、练习

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/

6、部署Nginx

1、yum安装
[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

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

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

9、Nginx配置文件

全局配置和模块配置

1、全局配置
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 : 指定网址的索引文件

10、超级玛丽和象棋

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

框架5--nginx安装部署 上(web服务)的更多相关文章

  1. hue框架介绍和安装部署

    大家好,我是来自内蒙古的小哥,我现在在北京学习大数据,我想把学到的东西分享给大家,想和大家一起学习 hue框架介绍和安装部署 hue全称:HUE=Hadoop User Experience 他是cl ...

  2. Nginx作为静态资源web服务之防盗链

    Nginx作为静态资源web服务之防盗链 首先,为什么需要防盗链,因为有些资源存在竞争对手的关系,比如淘宝的商品图片,不会轻易的让工具来爬虫爬走收集.但是如果使用防盗链,需要知道上一个访问的资源,然后 ...

  3. Nginx之静态资源WEB服务

    本篇主要记录学习Nginx的静态资源WEB服务的几种常见的功能记录学习 Nginx开发常用的命令 nginx -tc /etc/nginx/nginx.conf vim /etc/nginx/conf ...

  4. nginx 作为静态资源web服务

    Nginx作为静态资源web服务 静态资源web服务-CDN场景 Nginx资源存储中心会把静态资源分发给“北京Nginx”,“湖南Nginx”,“山东Nginx”. 然后北京User发送静态资源请求 ...

  5. Nginx作为静态资源web服务之跨域访问

    Nginx作为静态资源web服务之跨域访问 首先了解一下什么是跨域 跨域,指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器施加的安全限制. 所谓同源是指,域名,协议,端口均相 ...

  6. Nginx作为静态资源web服务之文件读取

    Nginx作为静态资源web服务之文件读取 文件读取会使用到以下几个配置 1. sendfile 使用nginx作为静态资源服务时,通过配置sendfile可以有效提高文件读取效率,设置为on表示启动 ...

  7. Nginx作为静态资源web服务之缓存原理

    Nginx作为静态资源web服务之缓存原理 大致理一下http浏览器缓存原理: 浏览器第一次请求服务器,此时浏览器肯定没有缓存,则直接调用服务器端,服务器在返回的信息的信息头中添加 ETag和Last ...

  8. 【JVM】linux上tomcat中部署的web服务,时好时坏,莫名其妙宕机,报错:There is insufficient memory for the Java Runtime Environment to continue.

    =========================================================================================== 环境: linu ...

  9. 使用uwsgi 部署python web服务

    uwsgi, wsgi协议的一个很好的实现,源码在这里:https://github.com/unbit/uwsgi c语言编写,有兴趣可以研究下. 上DEMO: wsgi_server.py def ...

随机推荐

  1. 学习git&github

    详细学习视频: 链接:https://pan.baidu.com/s/1Vub3YTo7uUUuGCJUCabBRQ 提取码:6q9x 一.git基本工作流程 我们先来理解下Git 工作区.暂存区和版 ...

  2. springboot 配置 swagger2

    1.pom.xml 添加依赖 <!--swagger2 依赖--> <dependency> <groupId>io.springfox</groupId&g ...

  3. c# - 一个.cs类文件里如何建多个类

    方法类可以使用 internal 修饰符,意为接口类, 主函数建议添加私有修饰符 private   控制台打印

  4. antd中的form表单 initialValue导致数据不更新问题

    初步理解 : initialValue就是所谓的defaultValue,只会在第一次赋值的时候改变,却又有一些不同,因为 initialValue又会因其他改动而改变. 然而当获取的数据重新上来要渲 ...

  5. SCALA-基础知识学习(一)

    概述 本人开始学习scala的时候,是在使用和开发spark程序的时候,在此为了整理.记录和分享scala的基础知识,我写这篇关于scala的基础知识,希望与广大读者共同学习沟通进步.如果有些代码比较 ...

  6. k个鸡蛋从N楼层摔,如果确定刚好摔碎的那个楼层,最坏情况下最少要试验x次?

    题目 k个鸡蛋从N楼层摔,如果确定刚好摔碎的那个楼层,最坏情况下最少要试验x次? 换个说法: k个鸡蛋试验x次最多可以检测N层楼.计算出N? 逆向思维和数学公式解. 分析 定义N(k,x) 如果第k个 ...

  7. unity3d发布安卓出错plese set the package name

    发布时报错 参考https://forum.unity.com/threads/where-is-package-name-setting.318839/ 参考https://answers.unit ...

  8. RT-Thread移植到stm32

    一.移植RT-Thread准备 RT-Thread源码 源码版本和下载方式,可以参考RT-Thread移植入门学习. keil软件 STM32工程项目模板 因为每一厂家提供的库文件可能有一些区别,在移 ...

  9. python中grpc配置asyncio使用

    python中grpc配置asyncio使用 安装grpclib pip3 install grpclib protoc编译.proto文件,生成源码文件 python -m grpc_tools.p ...

  10. golang中的配置管理库viper

    viper简介 Viper是适用于Go应用程序的完整配置解决方案.它旨在在应用程序中工作,并且可以处理所有类型的配置需求和格式.它支持: 设置默认值 从JSON,TOML,YAML,HCL,envfi ...