Virtual Host

基于域名的虚拟主机

准备站点目录

mkdir -p /application/nginx/html/www

mkdir -p /application/nginx/html/blog

mkdir -p /application/nginx/html/bbs

编辑配置文件

egrep -v "^$|#" nginx.conf.default > nginx.conf


vim /application/nginx/conf/nginx.conf

# 最终配置如下

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.imaginist.xyz;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  blog.imaginist.xyz;
        location / {
            root   html/blog;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  bbs.imaginist.xyz;
        location / {
            root   html/bbs;
            index  index.html index.htm;
        }
    }
}

# 修改配置如下:
# server_name  www.imaginist.xyz;
# root   html/www;

修改默认主页文件

添加 hosts 解析

添加 nginx 目录至环境变量

检查并重启

访问测试

使用别名

基于端口的虚拟主机

检查并重启

访问测试

Last updated