服務(wù)器部署之虛擬機(jī)安裝nginx并部署web網(wǎng)頁(yè)
1、先上成品圖

2、安裝Nginx運(yùn)行所需插件:
gcc:gcc編譯器用于編譯編程語(yǔ)言。
//通過(guò)gcc -v查看版本,如果有就不管【CentOS7是有的】 gcc -v //如果沒(méi)有g(shù)cc就通過(guò)下面的命令安裝 yum -y install gcc
安裝截圖:

zlib解壓軟件:
zlib庫(kù)是用于解壓和壓縮的。nginx下載下來(lái)是壓縮包,需要解壓。
安裝命令: yum install -y zlib zlib-devel
安裝截圖:

pcre、pcre-devel插件:
pcre是正則表達(dá)式的庫(kù),nginx中http模塊需要用到pcre解析正則表達(dá)式。安裝命令: yum install -y pcre pcre-devel
安裝截圖:

openssl插件:
網(wǎng)絡(luò)通信加密插件。安裝命令: yum install -y openssl openssl-devel
安裝截圖:

3、安裝Nginx
從官網(wǎng)下載壓縮包,需要用到wget軟件,CentOS7都自帶有,如果沒(méi)有的話,通過(guò)下面命令安裝。
yum install wget
下載Nginx安裝包:
wget http://nginx.org/download/nginx-1.21.6.tar.gz
通過(guò)命令ll查看本地會(huì)多一個(gè)文件:

解壓壓縮包:
tar -zxvf nginx-1.21.6.tar.gz
解壓后,通過(guò)命令ll查看,得到一個(gè)文件夾:

編譯安裝:
??????①、先進(jìn)入到解壓得到的nginx-1.21.6文件夾里面:cd nginx-1.21.6

②、執(zhí)行./configure文件,編譯nginx環(huán)境,使其之后的nginx就安裝到/usr/local/nginx目錄下:

③、繼續(xù)執(zhí)行命令:
# 在當(dāng)前目錄下執(zhí)行 make & make install

到這里,關(guān)于nginx已經(jīng)安裝好了,我們可以查看一下,多了些什么東西:

4、啟動(dòng)Nginx:
- 如果要啟動(dòng)Nginx,需要找到其啟動(dòng)命令,先進(jìn)入到命令所在的文件夾:
命令: cd /usr/local/nginx/sbin/
nginx這個(gè)就是啟動(dòng)命令。
關(guān)閉防火墻,不然啟動(dòng)之后訪問(wèn)不了,關(guān)閉防火墻命令:
systemctl stop firewalld.service
啟動(dòng)nginx(不要離開(kāi)/usr/local/nginx/sbin/):
./nginx
通過(guò)宿主機(jī)瀏覽器訪問(wèn):

5、更改主頁(yè)信息
到這里,nginx已經(jīng)安裝并且啟動(dòng)好了,那么接下來(lái)我們可以將這個(gè)頁(yè)面更改一番,在這里我提供了一段html代碼。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>圖片位置拖拽</title>
<style>
#main {
display: flex;
justify-content: center;
}
.img {
width: 100px;
user-select: none;
height: 100px;
background: no-repeat center center;
background-size: cover;
}
.bg1 {
background-image: url('https://cdn.pixabay.com/photo/2020/02/05/22/01/bush-4822500__480.jpg')
}
.bg2 {
background-image: url('https://cdn.pixabay.com/photo/2022/01/24/13/51/temple-6963458__480.jpg')
}
.bg3 {
background-image: url('https://cdn.pixabay.com/photo/2020/12/02/01/06/chipmunk-5795916__480.jpg')
}
.zw {
background-color: #999;
width: 100px;
height: 100px;
display: none;
}
</style>
</head>
<body>
<div id="main">
<span class="img bg1" data-index="0"></span>
<span class="img bg2" data-index="1"></span>
<span class="img bg3" data-index="2"></span>
<span class="zw"></span>
</div>
</body>
<script>
const imgs = document.querySelectorAll('.img')
const main = document.querySelector('#main')
const zw = document.querySelector('.zw')
const isMobile = navigator.userAgent.match(/Mobile/)
let isDrag = false
let index
let py = {
left: 0,
top: 0
}
const move = (el, x, y) => {
el.setAttribute('style', `pointer-events:none;position:absolute;left:${x}px;top:${y}px`)
}
document.addEventListener(isMobile ? 'touchstart' : 'mousedown', e => {
isMobile && (e = e.touches[0])
index = e.target.dataset.index
if (index && !isDrag) {
py.left = e.pageX - imgs[index].offsetLeft
py.top = e.pageY - imgs[index].offsetTop
zw.style.display = 'block'
main.insertBefore(zw, imgs[index])
move(imgs[index], e.pageX - py.left, e.pageY - py.top)
}
isDrag = true
})
document.addEventListener(isMobile ? 'touchmove' : 'mousemove', e => {
isMobile && (e = e.touches[0])
if (isDrag && index) {
move(imgs[index], e.pageX - py.left, e.pageY - py.top)
}
})
document.addEventListener(isMobile ? 'touchend' : 'mouseup', e => {
isDrag = false
zw.style.display = ''
if (imgs[index]) {
imgs[index].setAttribute('style', '')
main.insertBefore(imgs[index], zw)
}
})
imgs.forEach(v => {
v.addEventListener(isMobile ? 'touchmove' : 'mouseenter', e => {
isMobile && (e = e.touches[0])
if (isDrag) {
const list = [...main.children]
const imgIndex = list.findIndex(el => v == el)
const zwIndex = list.findIndex(el => zw == el)
if (zwIndex < imgIndex) {
main.insertBefore(v, zw)
} else {
main.insertBefore(zw, v)
}
}
})
})
</script>
</html>找到nginx的index.html
頁(yè)面在:/usr/local/nginx/html/這個(gè)文件夾里面cd /usr/local/nginx/html/


將我前面準(zhǔn)備好的一段代碼,替換掉原本的代碼:
自己操作,刪除,再粘貼
再次在宿主機(jī)瀏覽器中搜索

到這里,我們自己的html頁(yè)面就放進(jìn)來(lái)了。
6、目錄結(jié)構(gòu)
nginx安裝完成后,nginx里面的目錄結(jié)構(gòu)如下:

重點(diǎn)目錄和文件如下:
| 目錄/文件 | 說(shuō)明 |
| conf | 配置文件存放目錄 |
| conf/nginx.conf | nginx核心配置文件 |
| html | 存放靜態(tài)資源(html,css,js) |
| logs | 存放nginx日志 |
| sbin/nginx | 二進(jìn)制文件,用于啟動(dòng)/停止Nginx |
nginx更多知識(shí)還需要更系統(tǒng)的學(xué)習(xí),目前這個(gè)小demo就到這里了,bye~~~
總結(jié)
到此這篇關(guān)于服務(wù)器部署之虛擬機(jī)安裝nginx并部署web網(wǎng)頁(yè)的文章就介紹到這了,更多相關(guān)虛擬機(jī)安裝nginx部署web網(wǎng)頁(yè)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx stub_status 監(jiān)控模塊的功能實(shí)現(xiàn)
本篇文章主要介紹了Nginx stub_status 監(jiān)控模塊的功能實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
通過(guò)lua來(lái)配置實(shí)現(xiàn)Nginx服務(wù)器的防盜鏈功能
這篇文章主要介紹了通過(guò)lua來(lái)配置實(shí)現(xiàn)Nginx服務(wù)器的防盜鏈功能的方法,這里主要講解生成鏈接的Nginx配置,需要的朋友可以參考下2016-01-01
Nginx?配置?WebSocket?代理的操作過(guò)程
這篇文章主要介紹了Nginx?配置?WebSocket?代理的操作過(guò)程,本文給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-04-04
nginx配置客戶端保存cookie的實(shí)現(xiàn)
本文主要介紹了nginx配置客戶端保存cookie的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03
Python的Bottle框架基本知識(shí)總結(jié)
這篇文章主要介紹了Python的Bottle框架基本知識(shí)總結(jié),本文翻譯自Bottle官方開(kāi)發(fā)文檔,需要的朋友可以參考下2015-05-05
Nginx可視化管理軟件(Nginx Proxy Manager)的使用
Nginx Proxy Manager是一款開(kāi)源的Nginx可視化管理界面,本文就來(lái)介紹一下Nginx Proxy Manager的使用,感興趣的可以了解一下2024-03-03
Nginx配置移動(dòng)端和PC端自動(dòng)跳轉(zhuǎn)方式
文章介紹了如何通過(guò)Nginx配置PC端和移動(dòng)端自動(dòng)跳轉(zhuǎn),PC端和移動(dòng)端各有獨(dú)立的域名,PC端訪問(wèn)任何域名時(shí)會(huì)跳轉(zhuǎn)到www.yxf.com,移動(dòng)端訪問(wèn)任何域名時(shí)會(huì)跳轉(zhuǎn)到m.yxf.com,配置時(shí)需要修改Nginx的conf文件,使用302或301重定向2025-11-11
Nginx報(bào)Too Many Open Files總結(jié)
本文提供了解決Nginx服務(wù)器出現(xiàn)Too many open files錯(cuò)誤的方法,包括檢查和調(diào)整文件句柄限制、修改系統(tǒng)配置文件及nginx配置等,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2026-01-01

