Nginx 虛擬機如何安裝和使用
作者:佚名
nginx 虛擬機有不少的問題困擾著我們,首先就是在安裝中的問題,下面我們就看看如何才能更好的使用Nginx 虛擬機。
Nginx 虛擬機使用是廣大管理員需要掌握的相關問題,在使用中相關的問題需要我們不斷學習和掌握,下面我們就詳細的看看有關的問題。在Nginx 虛擬機中用多個子域名,每個子域名到不同的目錄。
如:
- http {
- server {
- listen 80;
- server_name a.chenlb.com;
- access_log logs/a.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /home/www/host_a/;
- }
- }
- server {
- listen 80;
- server_name b.chenlb.com;
- access_log logs/b.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /home/www/host_b/;
- }
- }
- }
- http {
- server {
- listen 80;
- server_name a.chenlb.com;
- access_log logs/a.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /home/www/host_a/;
- }
- }
- server {
- listen 80;
- server_name b.chenlb.com;
- access_log logs/b.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /home/www/host_b/;
- }
- }
- }
結果發現用 b.chenlb.com 還是指到 host_a 目錄。后來看了官方示例:http://wiki.Nginx.org/NginxVirtualHostExample,提到有個 default 的匹配,如:
- http {
- server {
- listen 80 default;
- server_name _;
- access_log logs/default.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /var/www/default/htdocs;
- }
- }
- }
- http {
- server {
- listen 80 default;
- server_name _;
- access_log logs/default.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /var/www/default/htdocs;
- }
- }
- }
加上這個 default 就可使 a.chenlb.com 和 b.chenlb.com 正常工作了。以上就是Nginx 虛擬機的詳細介紹。
【編輯推薦】
責任編輯:張浩
來源:
互聯網