Nginx實現虛擬機器

2021-07-31 02:08:45 字數 3639 閱讀 9678

區分不同的**有三種方式:

1、ip區分

方法一:

使用標準的網路配置工具(比如ifconfig和

route

命令)新增

lp別名:

當前ip配置情況:

在eth0網絡卡再繫結乙個ip:

方法二:

1、將/etc/sysconfig/network-scripts/ifcfg-eth0檔案複製乙份,命名為

ifcfg-eth0:1

修改其中內容:

device=eth0:1

ipaddr=192.168.25.103

其他項不用修改

2、重啟系統

nginx的配置檔案

server { #乙個

server

就是乙個虛擬主機

listen       80;

server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {

root   html;

index  index.html index.htm;

基於ip的虛擬主機配置

server {

listen       80;

server_name  192.168.25.141;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {

root   html-141;

index  index.html index.htm;

server {

listen       80;

server_name  192.168.25.100;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {

root   html-100;

index  index.html index.htm;

2、埠區分

server {

listen       81;

server_name  192.168.25.141;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {

root   html-81;

index  index.html index.htm;

server {

listen       82;

server_name  192.168.25.141;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {

root   html-82;

index  index.html index.htm;

3、網域名稱區分

最有用的虛擬主機配置方式。

乙個網域名稱只能繫結乙個ip位址,乙個

ip位址可以被多個網域名稱繫結。

可以修改host檔案實現網域名稱訪問。

可通過軟體修改,無需許可權,訪問目錄等(此軟體)

也可訪問目錄(

c:\windows\system32\drivers\etc

)修改window

的hosts

檔案。

基於網域名稱的虛擬主機配置

server {

listen       80;

server_name  www.itheima.com;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {

root   html-www;

index  index.html index.htm;

server {

listen       80;

server_name  hehe.itheima.com;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {

root   html-hehe;

index  index.html index.htm;

Nginx配置虛擬機器

2.配置虛擬機器 1 通過埠號區分虛擬機器 1 由於nginx安裝預設埠號 80,且server配置如下 server 2 配置另乙個埠號 81,新增server配置 server 3 複製html並重命名為html defferent,並修改html defferent中index.html為in...

虛擬機器Nginx部署

設定虛擬機器網絡卡為橋接模式 修改網絡卡配置檔案前,先關閉服務 配置靜態ip esc wq回車 儲存退出 重啟網路服務 systemctl restart network ping www.baidu.com 進行測試 如出現 ping unknown host www.baidu.com vi e...

nginx虛擬機器配置

全域性配置worker processes 1 有乙個工作的子程序,可自行修改 一般設定為 cpu數 核數 一般是nginx的連線特性event server2 server.舉例server error page 500 502 503 504 50x.html location 50x.html...