這裏介紹的是如何讓Nginx實現基於域名的虛擬主機
修改window的hosts文件:(C:\Windows\System32\drivers\etc) 需要管理員權限才能修改
這裏介紹一個很方便應用來修改host文件 SwitchHosts 底下有下載鏈接
運行時也需要以管理員身份運行(win8以上)
可以添加不同的方案,右下角爲應用此方案
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name www.xiaoyin.com; #charset koi8-r; #access_log logs/host.access.log main; location / { root html-xiaoyin; index index.html index.htm; } } server { listen 80; server_name www.xiaoxian.com; #charset koi8-r; #access_log logs/host.access.log main; location / { root html-xiaoxian; index index.html index.htm; } } }配置文件中有兩個server代表來個服務,配置了不同的域名,其中指向的根目錄也不相同(主要是首頁的標題修改了一下)