nginx啟動、配置及測試圖文詳解(全網(wǎng)最全)
更新時間:2024年02月01日 09:29:24 作者:Computer?Virus
nginx是一個輕量級的網(wǎng)頁服務器、方向代理服務器和電子郵件代理服務器,具有配置靈活、靜態(tài)資源高并發(fā)、系統(tǒng)資源占用少、擁有緩存服務等優(yōu)點,這篇文章主要給大家介紹了關于nginx啟動、配置及測試的相關資料,需要的朋友可以參考下
一、要求
1.配置不同IP訪問
2.配置不同端口訪問
3.配置域名訪問
二、前期準備
1.安裝gcc g++的依賴庫
yum -y install gcc gcc-c++

2.安裝 pcre的依賴庫
yum -y install pcre pcre-devel

3.安裝zlib的依賴庫
yum -y install zlib zlib-devel

4.安裝openssl的依賴庫
yum -y install openssl openssl-devel

5.解壓nginx的安裝包
tar -zxvf nginx-1.24.0.tar.gz

6.進入到解壓的nginx安裝目錄里面
cd nginx-1.24.0/

7.將nginx安裝到/usr/local/下
./configure --prefix=/usr/local/

8.編譯
make
make install


9.進入到nginx的安裝目錄
cd /usr/local/nginx

10.進入到nginx的sbin模塊,并且啟動nginx
cd sbin/ ./nginx

11.查看啟動是否成功
ps -ef | grep nginx


三、配置nginx
1.配置兩個網(wǎng)卡(192.168.191.100和192.168.191.200)
nmcli connection modify ens33 +ipv4.addresses 192.168.191.100/24 nmcli connection modify ens33 +ipv4.addresses 192.168.191.200/24

2.啟動ens33網(wǎng)卡
nmcli connection up ens33

3.進入 /usr/local/nginx/html/配置我們的網(wǎng)頁內容
cd /usr/local/nginx/html/
4.創(chuàng)建文件
make ip make name make port

5.在文件下創(chuàng)建相關文件

6.配置虛擬主機文件,進入到/usr/local/nginx/conf/
cd /usr/local/nginx/conf

7.編輯nginx.conf文件
vim nginx.conf

8.編輯以下內容
# ip 100
server {
listen 80;
server_name 192.168.191.100;
location / {
root /usr/local/nginx/html/ip/100;
index index.html;
}
}
# ip 200
server {
listen 80;
server_name 192.168.191.200;
location / {
root /usr/local/nginx/html/ip/200;
index index.html;
}
}
# port 100
server {
listen 100;
server_name 192.168.191.129;
location / {
root /usr/local/nginx/html/port/100;
index index.html;
}
}
# port 200
server {
listen 200;
server_name 192.168.191.129;
location / {
root /usr/local/nginx/html/port/200;
index index.html;
}
}
# www.jiege.com
server {
listen 80;
server_name www.jiege.com;
location / {
root /usr/local/nginx/html/name/jiege;
index index.html;
}
}
9.保存退出
10.配置虛擬機本地host文件
vim /etc/hosts

11.編輯以下內容
192.168.191.129 www.jiege.com

12.配置本機(windows 10)host文件 (C:\Windows\System32\drivers\etc的host文件)
192.168.191.129 www.jiege.com

13.啟動nginx
/usr/local/nginx/sbin/./nginx


四、測試
基于ip


基于端口


基于域名

五、總結
在ubuntu下安裝nginx也是同樣的配置
到此這篇關于nginx啟動、配置及測試的文章就介紹到這了,更多相關nginx啟動、配置、測試內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
解決nginx 503 Service Temporarily Unavailable方法示例
這篇文章主要介紹了解決nginx 503 Service Temporarily Unavailable方法示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-12-12
nginx快速部署一個網(wǎng)站服務(多域名+多端口)
本文主要介紹了nginx快速部署一個網(wǎng)站服務,并實現(xiàn)多域名和多端口,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-10-10
Nginx服務器中l(wèi)ocation配置的一些基本要點解析
這篇文章主要介紹了Nginx服務器中l(wèi)ocation配置的一些基本要點解析,特別對管理以及查找匹配作出了詳細的講解,需要的朋友可以參考下2015-12-12

