Nginx多虚拟主机日志定义
不同的ip
不同的端口
不同的域名
都可以访问到一台计算机的配置,nginx 的多虚拟主机的功能配置,利用虚拟主机可以在一台服务器上,运行多个站点 的配置,针对每个虚拟主机都配置好access.log更方便更清晰的对没一个虚拟主机进行访客信息管理
# 针对虚拟主机,添加日志的路径
server {
listen 80;
server_name learn_nginx_cc.com;
charset utf-8;
access_log logs/learn_nginx_cc.log;
location / {
root /www/learn_nginx_cc;
index index.html index.htm;
}
}第二个配置日志路径
server {
# 定义虚拟主机站点端口号
listen 80;
# 填写虚拟主机的域名配置,没有域名可以写 localhost
server_name learn_nginx.com;
# 给nginx定义网站的编码
charset utf-8;
access_log logs/learn_nginx.log;
# nginx的路径匹配规则
# 如下的规则是最低级匹配,任何的nginx请求,都会进入location配置,会去定义的目录中寻找>资料
location / {
# root关键词 是定义网页根目录,这个html是以nginx安装的路径为相对
root /www/vod;
# index关键词,定义nginx的首页文件名字,默认找index.html文件
index index.html index.htm;
}
}检测语法
[root@VM-4-2-centos conf]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
重新读取配置文件
[root@VM-4-2-centos conf]# nginx -s reload
查看日志目录下日志文件
[root@VM-4-2-centos logs]# pwd /usr/local/nginx/logs [root@VM-4-2-centos logs]# ll total 3084 drwxr-xr-x 3 root root 4096 Jul 28 17:45 2022 -rw-r--r-- 1 nobody root 34571 Jul 29 15:27 access.log -rw-r--r-- 1 root root 2153941 Jul 28 17:08 access.log_2022-07-28 -rw-r--r-- 1 nobody root 942378 Jul 29 15:28 error.log -rw-r--r-- 1 root root 0 Jul 29 15:27 learn_nginx_cc.log -rw-r--r-- 1 root root 0 Jul 29 15:27 learn_nginx.log -rw-r--r-- 1 root root 6 Jul 28 16:45 nginx.pid
查看日志文件
[root@VM-4-2-centos logs]# tail -f learn_nginx.log