web集群学习:源码安装nginx配置启动服务脚本、IP、端口、域名的虚拟主机

目录

1、源码安装nginx,并提供服务脚本。

2、配置基于ip地址的虚拟主机

 3、配置基于端口的虚拟主机

  4、配置基于域名的虚拟主机


1、源码安装nginx,并提供服务脚本。

1、源码安装会有一些软件依赖

(1)检查并安装 Nginx 基础依赖包 pcre-devel openssl-devel

# rpm -qa | egrep 'pcre-devel | openssl-devel'

(2)安装 Nginx 所需的 pcre 库 正则支持

pcre 的全称为 perl compatible regular expressions,中文译为 “ perl 兼容正则表达式”,官方站点为 http://www.pcre.org/, 安装 pere 库是为了使 Nginx 支持具备 URI 重写功能的 rewrite 模块,如果不安装 pere 库,则 Nginx 无法使用 rewrite 模块功能,Nginx的 rewrite 模块功能几乎是企业应用必须的。

yum install -y pcre-devel

(3) 安装 openssl-devel 加密支持
Nginx 在使用 HTTPS 服务的时候要用到此模块,如果不安装 openssl 相关包,安装Nginx 的过程中会报错。

yum install -y openssl-devel

(4)安装编译软件

yum install gcc gcc-c++ make -y

2、 nginx获取

RPM包获取:Index of /packages/

源码包获取:Index of /download/

(1)这里我选择的版本为nginx-1.22.0,通过wget安装

wget http://nginx.org/download/nginx-1.22.0.tar.gz

(2)解压nginx-1.22.0到指定文件夹

[root@node3 ~]# tar xf nginx-1.22.0.tar.gz -C /usr/local/src/
[root@node3 ~]# cd /usr/local/src/nginx-1.22.0/

(3)创建用户nginx 此处只设置便于不登录即可

useradd nginx -u 996 -r -g 1000 -s /sbin/nologin -c "nginx user"

 (4)开始安装 Nginx

[root@localhost nginx-1.22.0]# ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module 

(5)编译安装

make && make install

  (6)  为nginx提供SysV init脚本

[root@node3 nginx-1.22.0]# vim /usr/lib/systemd/system/nginx.service[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c   /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.target               

重新加载启动脚本并启动服务

 测验通过本机测试
显示此网页访问成功

2、配置基于ip地址的虚拟主机

1)需要先准备环境,创建站点目录

mkdir /usr/share/nginx/html/{bbs,blog}

2)创建主页文件

echo bbs test page > /usr/share/nginx/html/bbs/index.html
echo blog test page > /usr/share/nginx/html/blog/index.html

3)为网卡添加一个新的IP地址

nmcli connection modify ens32 +ipv4.addresses 192.168.80.151/24 ipv4.method manual autoconnect yes
nmcli connection up ens32 

3)去默认的配置文件配置基于ip地址的配置文件

vim /etc/nginx/conf.d/vhost.conf
server {listen      192.168.80.130:80;server_name  localhost;access_log  /var/log/nginx/bbs_access.log  main;error_log   /var/log/nginx/bbs_error.log;location / {root   /usr/share/nginx/html/bbs;index  index.html index.htm;}
}server {listen      192.168.80.151:80;server_name  localhost;access_log  /var/log/nginx/blog_access.log  main;error_log   /var/log/nginx/blog_error.log;location / {root   /usr/share/nginx/html/blog;index  index.html index.htm;}
}

检查语法

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

重启nginx并测试

 3、配置基于端口的虚拟主机

vim /etc/nginx/conf.d/vhost.conf
server {listen    81;server_name  localhost;access_log  /var/log/nginx/bbs_access.log  main;error_log   /var/log/nginx/bbs_error.log;location / {root   /usr/share/nginx/html/bbs;index  index.html index.htm;}
}server {listen    82;server_name  localhost;access_log  /var/log/nginx/blog_access.log  main;error_log   /var/log/nginx/blog_error.log;location / {root   /usr/share/nginx/html/blog;index  index.html index.htm;}
}

重启服务并浏览器访问

 

  4、配置基于域名的虚拟主机

vim /etc/nginx/conf.d/vhost.conf
server {listen      80;server_name  bbs.openlab.cn;access_log  /var/log/nginx/bbs_access.log  main;error_log   /var/log/nginx/bbs_error.log;location / {root   /usr/share/nginx/html/bbs;index  index.html index.htm;}
}
server {listen      80;server_name  blog.openlab.cn;access_log  /var/log/nginx/blog_access.log  main;error_log   /var/log/nginx/blog_error.log;location / {root   /usr/share/nginx/html/blog;index  index.html index.htm;}
}

为本地dns服务器做解析

vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.80.130 bbs.openlab.cn blog.openlab.cn

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/32275.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

数据结构刷题训练——链表篇(二)

目录 前言 1.题目一:链表分割 1.1 思路 1.2 分析 1.3 题解 2. 题目二:相交链表 2.1 思路 2.2 分析 2.3 题解 3. 题目三:环形链表 3.1 思路 3.2 分析 3.3 题解 总结 前言 本期继续分享链表相关的OJ题目,在这个专栏博客…

【论文阅读】EULER:通过可扩展时间链接预测检测网络横向移动(NDSS-2022)

作者:乔治华盛顿大学-Isaiah J. King、H. Howie Huang 引用:King I J, Huang H H. Euler: Detecting Network Lateral Movement via Scalable Temporal Graph Link Prediction [C]. Proceedings 2022 Network and Distributed System Security Symposium…

UDP通信实验、广播与组播、本地套接字

文章目录 流程函数应用广播应用 组播(多播)本地套接字应用 流程 函数 返回值: 成功,返回成功发送的数据长度 失败,-1 返回值: 成功,返回成功接收数据长度 失败,-1 应用 广播 应用 …

MongoDB文档-进阶使用-MongoDB索引-createindex()与dropindex()-在MongoDB中使用正则表达式来查找

阿丹: 之前研究了MongoDB的基础增删改查。在学会基础的数据库增删改查肯定是不够的。这个时候就涉及到了数据库搜索的时候的效率。需要提高数据的搜索效率。 MongoDB索引 在所以数据库中如果没有数据索引的时候。如果需要查找到一些数据。都会去主动扫描所有可能存…

mybatis-plus的逻辑删除的坑

一旦在逻辑字段上加了TableLogic逻辑删除的配置,并且使用mybatis-plus自带的方法时(如果自己用xml写SQL不会出现下面的情况) 查询、修改时会自动排除逻辑删除的数据 当使用mybatis-plus自带的查询方法时,就不用每次查询的时候跟…

Blazor 简单组件(1):B_Icon开发

文章目录 前言ICON开发使用 前言 Blazor 简单组件(0)&#xff1a;简单介绍 ICON开发 <i class"Type" style"font-size:(Size)px;color:Color;"></i>code {/// <summary>/// icon类型/// </summary>[Parameter]public string Typ…

nginx 以及nginx优化

目录 nginx功能介绍 静态文件服务 反向代理 动态内容处理 SSL/TLS 加密支持 虚拟主机支持 URL 重写和重定向 缓存机制 日志记录 可扩展性和灵活性 nginx的主要应用场景 nginx常用命令 nginx另外一种安装方式 nginx常用的信号符&#xff1a; nginx配置文件详解 n…

Nginx复现

docker复现Nginx配置漏洞 2.1CRLF(carriage return/line feed)注入漏洞 这个漏洞产生的原因是请求重定向的错误配置&#xff0c;导致在url中输入回车换行符可以控制http响应头部 比如&#xff1a;location / { return 302 https://$host$uri; } 原本的目的是为了让http的…

【JavaEE基础学习打卡02】是时候了解JavaEE了

目录 前言一、为什么要学习JavaEE二、JavaEE规范介绍1.什么是规范&#xff1f;2.什么是JavaEE规范&#xff1f;3.JavaEE版本 三、JavaEE应用程序模型1.模型前置说明2.模型具体说明 总结 前言 &#x1f4dc; 本系列教程适用于JavaWeb初学者、爱好者&#xff0c;小白白。我们的天…

c#在设计时调试自定义 Windows 窗体控件

private string demoStringValue null; [Browsable(true)] public string DemoString {get{return this.demoStringValue;}set{demoStringValue value;} } 参考链接 在设计时调试自定义控件 - Windows Forms .NET Framework | Microsoft Learnhttps://learn.microsoft.com/z…

生信豆芽菜——配对型的复杂箱线图使用说明

网站&#xff1a;http://www.sxdyc.com/visualsBoxHalfPlot 一、配对型的复杂箱线图简介 配对型的复杂箱线图原理与箱线图相同&#xff0c;常见于配对样本的数据分析中&#xff0c;在日常研究中&#xff0c;我们会碰到配对资料&#xff0c;例如同一病人治疗前后的变化&#xff…

数据结构: 线性表(带头双向循环链表实现)

之前一章学习了单链表的相关操作, 但是单链表的限制却很多, 比如不能倒序扫描链表, 解决方法是在数据结构上附加一个域, 使它包含指向前一个单元的指针即可. 那么怎么定义数据结构呢? 首先我们先了解以下链表的分类 1. 链表的分类 链表的结构非常多样, 以下情况组合起来就有…

LVS集群

目录 1、lvs简介&#xff1a; 2、lvs架构图&#xff1a; 3、 lvs的工作模式&#xff1a; 1&#xff09; VS/NAT&#xff1a; 即&#xff08;Virtual Server via Network Address Translation&#xff09; 2&#xff09;VS/TUN &#xff1a;即&#xff08;Virtual Server v…

7.2 手撕VGG11模型 使用Fashion_mnist数据训练VGG

VGG首先引入块的思想将模型通用模板化 VGG模型的特点 与AlexNet&#xff0c;LeNet一样&#xff0c;VGG网络可以分为两部分&#xff0c;第一部分主要由卷积层和汇聚层组成&#xff0c;第二部分由全连接层组成。 VGG有5个卷积块&#xff0c;前两个块包含一个卷积层&#xff0c…

MySQL_SQL性能分析

SQL执行频次 语法&#xff1a; SHOW GLOBAL STATUS LIKE COM_类型; COM_insert; 插入次数 com_delete; 删除次数 com_update; 更新次数 com_select; 查询次数 com_______; 注意&#xff1a;通过语法&#xff0c;可以查询到数据库的实际状态&#xff0c;就可以知道数据库是以增删…

TDesign中后台管理系统-用户登录

目录 1 创建用户表2 开发后端接口3 测试接口4 修改登录页面调用后端接口最终效果总结 中后台系统第一个要实现的功能就是登录了&#xff0c;我们通常的逻辑是让用户在登录页面输入用户名和密码&#xff0c;调用后端接口去验证用户的合法性&#xff0c;然后根据接口返回的结果进…

【T3】金蝶kis凭证数据转换到畅捷通T3软件中。

【问题需求】 将金蝶软件中的账套转换到畅捷通T3软件中。 由于金蝶老版本使用的是非sql server数据库。 进而需要将其数据导入到sql中,在转换到T3。 【转换环境】 金蝶中数据:凭证;科目无项目核算。 1、金蝶的数据文件后缀为.AIS; 2、安装office2003全版软件; 3、安装sq…

【算法】双指针——leetcode盛最多水的容器、剑指Offer57和为s的两个数字

盛水最多的容器 &#xff08;1&#xff09;暴力解法 算法思路&#xff1a;我们枚举出所有的容器大小&#xff0c;取最大值即可。 容器容积的计算方式&#xff1a; 设两指针 i , j &#xff0c;分别指向水槽板的最左端以及最右端&#xff0c;此时容器的宽度为 j - i 。由于容器…

【CDH集群】无法发出查询:Host Monitor未运行

无法发出查询:Host Monitor未运行 【CDH集群】无法发出查询:Host Monitor未运行同事的解决方案解决方法&#xff1a;删除原uuid重启agent查看新uuid修改scm数据库中HOSTS表中的agent的uuid 【CDH集群】无法发出查询:Host Monitor未运行 起初是impala报错&#xff0c;连接不上&…

使用 React Native CLI 创建项目

React Native 安装的先决条件和设置 需要掌握的知识点 掌握 JavaScript 基础知识掌握 React 相关基础知识掌握 TypeScript 相关基础知识 安装软件前需要首先安装Chocolatey。Chocolatey 是一种流行的 Windows 包管理器。 安装 nodejs 和 JDK choco install -y nodejs-lts …