vhost配置文件的作用
vhost配置文件的作用是為了將更多的server配置文件的信息祭埂,單獨(dú)存放,不過于集中在nginx.conf配置中弓柱,這樣有助于查找問題
nginx安裝目錄
修改nginx.conf
http塊中添加include vhosts/*.conf;
#user nobody;
worker_processes 1;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /data/lightkits-web/html;
try_files $uri /index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# 將vhosts目錄下所有conf結(jié)尾的文件配置加載到nginx.conf
# 注意vhosts的
include vhosts/*.conf;
}
在nginx目錄下的vhosts目錄中新增conf
cd vhosts
touch welink.conf
文件內(nèi)容如下
server {
default_type 'text/html';
charset utf-8;
listen 8070; # 監(jiān)聽的端口號(hào)
autoindex off;
server_name localhost; #監(jiān)聽的域名
# 存放nginx日志的路徑
access_log /usr/src/nginx/logs/welink.log combined;
index index.html index.htm index.jsp index.php;
#error_page 404 /404.html
if ( $query_string ~* ".*[\;'\<\>].*" ) {
return 404;
}
location / {
index index.html; # 請求入口文件
root /data/welink/dist/; # 請求的目錄
}
}
注意:編輯conf文件時(shí)沟堡,每行的末尾用分號(hào);分隔開
將要發(fā)布的web應(yīng)用存放在location指定的目錄
測試nginx.conf配置文件是否正確
nginx -t
重新加載配置文件重啟
nginx -s reload