Apache/Nginx的虚拟主机

Apache

在Apache的的主配置文件httpd.conf中进行修改:

Include /etc/httpd/conf/extra/httpd-vhosts.conf     //170line
        ##表示包括我所设定的虚拟主机文件爱你

在自己所创立文件中进行添加:

80>
ServerName  www.westos.com      #主机名,它通过LB上的参数被检测到
ServerAlias www.hello.com       #主机别名
DocumentROot    "/var/www/html"     #该域名的家目录
ServerAdmin 91XXXXXXXqq.com     #该域名管理者的邮箱
ErrorLog    "/var/log/httpd-Error.log"  "日志格式"#出错日志
CustomLog   "/var/log/httpdCustom.log"  "日志格式" 访问日志



80>
ServerName  www.etiantian.org
DocumentROot    "/var/www/www"
ServerAdmin 917785844@qq.com


80>
ServerName  blog.etiantian.org
DocumentROot    "/var/www/blog"
ServerAdmin 917785844@qq.com


80>
ServerName  bbs.etiantian.org
DocumentROot    "/var/www/bbs"
ServerAdmin 917785844@qq.com

另外需要在hosts或resolve下解析主机名,在此不再多说。

Nginx

基于端口:
只需改动port即可
基于域名:
同样在nginx的主配置文件中http模块里添加

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

include extra/bbs.conf;     ##这三个为虚拟主机文件
include extra/www.conf;
include extra/blog.conf;
}

在创建所创建的文件:

server{
        listen 80;
        server_name bbs.etiantian.org;
location / {
         index index.html;
         root /usr/local/nginx/bbs;
                }
        }

最后别忘了解析。

基于IP的:
将servername后面的域名改为虚拟IP

你可能感兴趣的:(Apache/Nginx的虚拟主机)