CentOS 7.3配置Nginx虛擬主機的方法步驟
實驗環(huán)境
一臺最小化安裝的CentOS 7.3虛擬機
配置基本環(huán)境
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配置文件
vim /etc/nginx/conf.d/vhosts.conf
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配置文件
vim /etc/nginx/conf.d/vhosts.conf
2. 刪除原內容,重新添加以下內容
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
服務
systemctl restart nginx
4. 在Windows上修改 hosts
文件
編輯 C:\Windows\System32\drivers\etc\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配置文件
vim /etc/nginx/conf.d/vhosts.conf
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
服務
systemctl restart nginx
5. 在宿主機訪問兩個站點
http://192.168.204.151/
http://192.168.204.152/
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- 阿里云Centos7安裝svn與配置講解
- CentOS7將Nginx添加系統(tǒng)服務的方法步驟
- Centos7.x下Nginx安裝及SSL配置與常用命令詳解
- centos6.5安裝python3.7.1之后無法使用pip的解決方案
- CentOS版本問題安裝Docker報錯的解決方案
- Centos7修改主機名hostname的三種方法
- Linux centos下設置定時備份任務的方法步驟
- Linux centOS安裝JDK和Tomcat的教程
- 在CentOS7上搭建Jenkins+Maven+Git持續(xù)集成環(huán)境的方法
- Centos7.5配置java環(huán)境安裝tomcat的講解
相關文章
Linux在批量服務器管理中實用的PS1命令提示符格式實現方法
PS1是神馬?PS1是linux里頭的一個默認的環(huán)境變量,至于當前系統(tǒng)的PS1是如何設置的,你可以使用命令“env|grep PS1”來查看2015-09-09linux用戶source .bashrc或.profile找不到文件的解決
這篇文章主要介紹了linux用戶source .bashrc或.profile找不到文件的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04