Nginx 虛擬機(jī)如何安裝和使用
Nginx 虛擬機(jī)使用是廣大管理員需要掌握的相關(guān)問(wèn)題,在使用中相關(guān)的問(wèn)題需要我們不斷學(xué)習(xí)和掌握,下面我們就詳細(xì)的看看有關(guān)的問(wèn)題。在Nginx 虛擬機(jī)中用多個(gè)子域名,每個(gè)子域名到不同的目錄。
如:
- 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/;
- }
- }
- }
結(jié)果發(fā)現(xiàn)用 b.chenlb.com 還是指到 host_a 目錄。后來(lái)看了官方示例:http://wiki.Nginx.org/NginxVirtualHostExample,提到有個(gè) 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;
- }
- }
- }
加上這個(gè) default 就可使 a.chenlb.com 和 b.chenlb.com 正常工作了。以上就是Nginx 虛擬機(jī)的詳細(xì)介紹。
【編輯推薦】
- Nginx設(shè)置404相關(guān)問(wèn)題代碼答疑
- Nginx 502錯(cuò)誤兩種解決方案介紹
- Nginx反向代理的安裝和測(cè)試的基本流程
- Nginx日志在PHP中的優(yōu)化技巧
- Nginx參數(shù)站點(diǎn)配置上的問(wèn)題解決方案