在Nginx配置目录下,创建一个”vhost”目录,编译安装的目录可以指定
mkdir /usr/local/nginx/vhost
创建配置文件
vim /usr/local/nginx/vhost/vhost_siteA.conf
添加以下配置:证书可以去阿里云申请,或者注释HTTPS
server {
listen 8080; # 监听端口
# server_name www.siteA.com siteA.com; # 站点域名
root /home/user/www/blog; # 站点根目录
rewrite ^(.*)$ https://$host$1 permanent; #转向https
location ~ / {
root /home/user/www/blog;
index index.html index.htm;
}
}
server {
listen 443 ssl;
server_name testa.inewmaker.com;
ssl_certificate cert/2012001_testa.inewmaker.com.pem; #SSL证书
ssl_certificate_key cert/2012001_testa.inewmaker.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /home/user/www/blog;
index index.html index.htm;
}
}
创建不同的配置文件,两者仅有的不同是”server_name”和”root”目录,监听端口,SSL证书(因申请的免费证书需要指定对应域名或者购买通配证书则可以使用相同证书)
vim /usr/local/nginx/vhost/vhost_siteB.conf
server {
listen 8090; # 监听端口
#server_name www.siteB.com siteB.com; # 站点域名
root /home/user/www/forum; # 站点根目录
...
}
server {
listen 443 ssl;
server_name testa.inewmaker.com; # 站点域名
ssl_certificate cert/2011001_testb.inewmaker.com.pem; #SSL证书
ssl_certificate_key cert/2011001_testb.inewmaker.com.key;
root /home/user/www/forum; # 站点根目录
打开nginx.conf文件
vim /usr/local/nginx/conf/nginx.conf
虚拟目录的配置文件加入到”http {}”部分的内
http {
include /usr/local/nginx/vhost/*.conf;
···
}
重启Nginx服务
cd /usr/local/nginx/sbin
./nginx -s reload
根据域名正常访问