實驗環境
一台最小化安裝的centos 7.3虛擬機
設定基本環境
1.安裝nginx
yum install -y epel-* yum isntall -y nginx vim
2. 建立虛擬機主機的網站根目錄
mkdir /var/wwwroot mkdir /var/wwwroot/site1 mkdir /var/wwwroot/site2 echo -e "site1" >> /var/wwwroot/site1/index.html echo -e "site2" >> /var/wwwroot/site2/index.html
3. 關閉centos的防火牆
setenforce 0 systemctl stop firewalld systemctl disable firewalld
設定基於連接埠的虛擬主機
1. 編輯nginx設定檔
<pre class='brush:php;toolbar:false;'>vim /etc/nginx/conf.d/vhosts.conf</pre>2. 新增以下內容
server { listen 8081; root /var/wwwroot/site1; index index.html; location / { } } server { listen 8082; root /var/wwwroot/site2; index index.html; location / { } }
#3. 啟動 nginx
服務
systemctl start nginx
4. 在宿主機器存取兩個網站
http://192.168 .204.135:8081/
#http://192.168.204.135:8082/
#
#設定基於網域的虛擬主機
1. 重新編輯nginx設定檔
<pre class='brush:php;toolbar:false;'>vim /etc/nginx/conf.d/vhosts.conf</pre>
server { listen 80; server_name site1.test.com; root /var/wwwroot/site1; index index.html; location / { } } server { listen 80; server_name site2.test.com; root /var/wwwroot/site2; index index.html; location / { } }
3. 重啟 nginx
服務
4. 在windows上修改
hosts 檔案#編輯
文件,新增以下內容(依實際情況自行修改)
#192.168.204.135 site1 .test.com
192.168.204.135 site2.test.com##5. 在宿主機上訪問兩個網站
http://site1.test.com/
http://site2.test.com/
配置基於ip的虛擬主機
1. 在虛擬機器增加兩個ip位址
ifconfig ens33:1 192.168.204.151 ifconfig ens33:2 192.168.204.152
2. 重新編輯nginx設定檔<pre class='brush:php;toolbar:false;'>vim /etc/nginx/conf.d/vhosts.conf</pre>
3. 刪除原始內容,重新新增下列內容
server { listen 192.168.204.151:80; root /var/wwwroot/site1; index index.html; location / { } } server { listen 192.168.204.152:80; root /var/wwwroot/site2; index index.html; location / { } }
4. 重新啟動
nginx
服務<pre class='brush:php;toolbar:false;'>systemctl restart nginx</pre>
5. 在宿主機造訪兩個網站
http://192.168.204.151/
#http://192.168. 204.152/
以上是CentOS7.3怎麼設定Nginx虛擬主機的詳細內容。更多資訊請關注PHP中文網其他相關文章!

NGINX和Apache各有優劣,適合不同場景。 1.NGINX適合高並發和低資源消耗場景。 2.Apache適合需要復雜配置和豐富模塊的場景。通過比較它們的核心特性、性能差異和最佳實踐,可以幫助你選擇最適合需求的服務器軟件。

確認 Nginx 是否啟動的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 檢查端口 80 是否開放;3. 查看系統日誌中 Nginx 啟動消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

要關閉 Nginx 服務,請按以下步驟操作:確定安裝類型:Red Hat/CentOS(systemctl status nginx)或 Debian/Ubuntu(service nginx status)停止服務:Red Hat/CentOS(systemctl stop nginx)或 Debian/Ubuntu(service nginx stop)禁用自動啟動(可選):Red Hat/CentOS(systemctl disable nginx)或 Debian/Ubuntu(syst

如何在 Windows 中配置 Nginx?安裝 Nginx 並創建虛擬主機配置。修改主配置文件並包含虛擬主機配置。啟動或重新加載 Nginx。測試配置並查看網站。選擇性啟用 SSL 並配置 SSL 證書。選擇性設置防火牆允許 80 和 443 端口流量。

服務器無權訪問所請求的資源,導致 nginx 403 錯誤。解決方法包括:檢查文件權限。檢查 .htaccess 配置。檢查 nginx 配置。配置 SELinux 權限。檢查防火牆規則。排除其他原因,如瀏覽器問題、服務器故障或其他可能的錯誤。

在 Linux 中啟動 Nginx 的步驟:檢查 Nginx 是否已安裝。使用 systemctl start nginx 啟動 Nginx 服務。使用 systemctl enable nginx 啟用在系統啟動時自動啟動 Nginx。使用 systemctl status nginx 驗證啟動是否成功。在 Web 瀏覽器中訪問 http://localhost 查看默認歡迎頁面。

在 Linux 中,使用以下命令檢查 Nginx 是否已啟動:systemctl status nginx根據命令輸出進行判斷:如果顯示 "Active: active (running)",則 Nginx 已啟動。如果顯示 "Active: inactive (dead)",則 Nginx 已停止。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。