ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Nginx 虚拟主机配置及日志详解

2020-05-16 17:05:40  阅读:197  来源: 互联网

标签:index 虚拟主机 server Nginx html conf 日志 root


虚拟主机管理

1.什么是nginx 虚拟主机

虚拟主机是一种特殊的软硬件技术,它可以将网络上的每一台计算机分成多个虚拟主机,
每个虚拟主机可以独立对外提供 www 服务,这样就可以实现一台主机对外提供多个 web 服务,
每个虚拟主机之间是独立的,互不影响。

2.Nginx 支持三种类型的虚拟主机配置

1.基于 IP 的虚拟主机  
2.基于域名的虚拟主机
3.基于端口的虚拟主机

配置文件server 标签写法

# server标签(虚拟主机)
server {
# 监听80端口
listen 80;
#域名
server_name localhost;
# 字符集
#charset koi8-r;
#日志
#access_log /var/log/nginx/host.access.log main;
#访问的是/
location / {
# 在/usr/share/nginx/html
root /usr/share/nginx/html;
#站点目录 = /usr/share/nginx/html;
# 默认找index.html页面或者index.htm 从左往右查找 index index.html index.htm; # 默认页面 = index.html || index.htm } # 错误页面 404 找站点目录下的404.html error_page 404 /404.html; # redirect server error pages to the static page /50x.html # # 错误页面 5xx的,访问站点目录下的50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
server {
#监听的端口
listen 80;
#域名,IP
server_name www.test.com;
# 所有的请求以/开始 匹配location
location / {
#站点目录 网页存放处
root /opt/test;
#欢迎页面 html页面 从左向右查询
index index.html index.htm;
}
}

基于多IP配置方式

1.单网卡多ip,和多网卡多ip   ##添加VIP

# 1.绑定虚拟IP给eth0
[root@web01 conf.d]# ifconfig eth0:0 10.0.0.100/24
[root@web01 conf.d]# ifconfig eth0:1 10.0.0.101/24

2.配置nginx

[root@web01 conf.d]# cat /etc/nginx/conf.d/www.zls.com_test.conf
server {
listen 80;
server_name 10.0.0.100;
location / {
root /yw1/html;
index index.html;
}
}
server {
listen 80;
server_name 10.0.0.101;
location / {
root /yw2/html;
index index.html;
}
}

基于多端口配置方式

[root@web01 conf.d]# cat /etc/nginx/conf.d/www.zls.com_test.conf
server {
listen 80;
server_name 10.0.0.100;
location / {
root /yw1/html;
index index.html;
}
}
server {
listen 81;
server_name 10.0.0.100;
location / {
root /yw2/html;
index index.html;
}
}

基于多域名配置方式

[root@web01 conf.d]# cat /etc/nginx/conf.d/www.zls.com_test.conf
server {
listen 80;
server_name www.yewu1.com;
location / {
root /yw1/html;
index index.html;
}
}
server {
listen 80;
server_name www.yewu2.com;
location / {
root /yw2/html;
index index.html;
}
}

 

标签:index,虚拟主机,server,Nginx,html,conf,日志,root
来源: https://www.cnblogs.com/goodsuperman/p/12901224.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有