nginx基礎配置(多個虛擬機器主機)

來源:互聯網
上載者:User

標籤:

nginx配置多個虛擬機器主機(mac)

 

1 . 安裝

 

   通過homebrew安裝nginx,預設安裝在:/usr/local/Cellar/nginx/版本號碼。設定檔在路徑:/usr/local/etc/nginx ,預設設定檔nginx.conf,這個檔案主要配置了localhost:8080這個,sudo nginx命令啟動nginx,在地址欄輸入localhost:8080,不出意外的話,就能訪問到預設的頁面,也就是nginx目錄下面的html/index.html。

 

2. 配置兩個虛擬機器主機

 

  首先在nginx配置目錄下(/usr/local/etc/nginx/)建立檔案夾sites-enabled,在這個檔案夾下面建立nginx-bob.conf,nginx-alice.conf,分別為我們即將床架的虛擬機器主機(bob.com    alice.com)的設定檔:

 

  nginx-alice.conf設定檔如下:

 

server {    listen 80;    server_name alice.com;    charset utf-8;        root /Users/bobo/www/alice/html;    location / {        index index.html index.htm index.php;    }} 

  nginx-bob.conf設定檔如下:  

server {    listen 80;    server_name alice.com;    charset utf-8;        root /Users/bobo/www/alice/html;    location / {        index index.html index.htm index.php;    }} 

3 讓設定檔生效

  在nginx.conf檔案倒數第二行添加 include sites-enabled/nginx-*.conf.

 

到現在為止,設定檔已經全部弄好了,需要製作兩個網站,在/User/bobo/www 分別建立bob和alice兩個網站,在裡面分別添加html/index.html 檔案,為了顯示不同最好講兩個index.html寫的有所區分,

好了重啟nginx     sudo nginx -s reload  訪問bob.com和alice.com就應該能看到剛才寫的兩個index.html頁面了。

注意:引文預設訪問的是80連接埠,如果你的網站配置的是8000連接埠的話,應該這樣訪問bob.com:8000.

God,忘了最重要的一個步驟了,修改hosts檔案,添加最後一行

  127.0.0.1    bob.com     

  127.0.0.1    alice.com

 

nginx基礎配置(多個虛擬機器主機)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.