
nginx绑定多个域名可又把多个域名规则写一个配置文件里,也可又分别建立多个域名配置文件,我一般为了管理方便,每个域名建一个文件,有些同类域名也可又写在一个总的配置文件里。
一、每个域名一个文件的写法
首先打开nginx域名配置文件存放目录:/usr/local/nginx/conf/servers ,如要绑定域名www.rodine.org 则在此目录建一个文件:www.rodine.org.conf然后在此文件中写规则,如:server
{listen 80
server_name www.rodine.org #绑定域名
index index.htm index.html index.php #默认文件
root /home/www/rodine.org #网站根目录
include location.conf #调用其他规则,也可去除
}
然后重起nginx服务器,域名就绑定成功了nginx服务器重起命令:/etc/init.d/nginx restart
二、一个文件多个域名的写法
一个文件添加多个域名的规则也是一样,只要把上面单个域名重复写下来就ok了,如:
server{
listen 80
server_name www.rodine.org #绑定域名
index index.htm index.html index.php #默认文件
root /home/www/rodine.org #网站根目录
include location.conf #调用其他规则,也可去除
}server
{
listen 80
server_name msn.rodine.org #绑定域名
index index.htm index.html index.php #默认文件
root /home/www/msn.rodine.org #网站根目录
include location.conf #调用其他规则,也可去除
}
三、不带www的域名加301跳转
如果不带www的域名要加301跳转,那也是和绑定域名一样,先绑定不带www的域名,只是不用写网站目录,而是进行301跳转,如:
server{
listen 80
server_namerodine.org
rewrite ^/(.*) http://www.rodine.org/$1 permanent
}
四、添加404网页
添加404网页,都可又直接在里面添加,如:
server{
listen 80
server_name www.rodine.org #绑定域名
index index.htm index.html index.php #默认文件
root /home/www/rodine.org #网站根目录
include location.conf #调用其他规则,也可去除
error_page 404 /404.html
}
学会上面四种规则方法,基本就可以自己独立解决nginx 多域名配置问题了
搜索引擎关键字:在线自签名SSL证书。自签名的证书不会被浏览器信任,如果用于小程序或者APP应用等开发,就没有办法,必须要买多域名通配符才可以。
申请多域名通配符SSL证书:
将确定需要的域名准备好。
进入淘宝里面找到:Gworg,选择通配符多域名SSL证书。
根据要求完成域名解析认证,获得证书配置即可。
有无解决办法:Gworg获得多域名通配符SSL证书。
1、这个问题和linux系统没关系2、用webserver的虚拟主机vhost
3、apache实例
<VirtualHost 172.16.1.2>
DocumentRoot /opt/www1
ServerName dns1
.......
</VirtualHost>
<VirtualHost 172.16.1.2>
DocumentRoot /opt/www2
ServerName dns2
.......
</VirtualHost>
4、nginx实例
server{
listen 80
server_name yourdomain1#绑定域名
index index.html#默认文件
root /opt/www#网站根目录
include proxy.conf#调用其他规则
}
server{
listen 80
server_name yourdomain2#绑定域名
index index.html#默认文件
root /opt/www#网站根目录
include proxy.conf#调用其他规则
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)