Nginx 多域名绑定

Nginx 多域名绑定

实现最终结果:一个ip绑定多个域名

准备

  • 安装好Nginx
    还未安装好可参考博主的另一文章:Nginx 安装与部署
  • 域名
    申请的域名需要实名验证备案通过才可以使用,详情咨询服务商

实现

  • 找到nginx.conf配置文件
# nginx安装位置查找
[root@VM_0_3_centos ~]# find / -name nginx.conf
/usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/beifen/nginx.conf
/root/nginx-1.13.1/conf/nginx.conf
# nginx配置文件所在地
[root@VM_0_3_centos ~]# cd /usr/local/nginx/conf/
[root@VM_0_3_centos conf]# ls
beifen                  koi-utf             nginx.conf.default    vhost
fastcgi.conf            koi-win             scgi_params           win-utf
fastcgi.conf.default    mime.types          scgi_params.default
fastcgi_params          mime.types.default  uwsgi_params
fastcgi_params.default  nginx.conf          uwsgi_params.default
  • 打开配置文件
[root@VM_0_3_centos conf]# vi nginx.conf
...
http{
	...
	#新增一句话 目录自定义
	#nginx会自动执行一遍vhost目录下的所有配置文件 使之生效
	include ./vhost/*.conf;
	server {
		...
	}
	...
}
...
  • 进入自定义路径中添加配置文件
    配置好 站点域名 网站运行的目录 网站运行的html
[root@VM_0_3_centos conf]# cd vhost/
[root@VM_0_3_centos vhost]# ls
nginx_fk.conf  nginx_hctf.conf  nginx_map.conf
[root@VM_0_3_centos vhost]# cat nginx_fk.conf 
server {
    listen       80;                        	# 监听端口
    server_name fk.creatorhy.com creatorhy.com; # 站点域名
    root  /usr/local/nginx/html/fangkuai/;  	# 站点根目录
    index index.html index.htm index.php;   	# 默认导航页
 
    location / {
        # WordPress固定链接URL重写
        if (!-e $request_filename) {
            rewrite (.*) /index.php;
        }
    }
 
    # PHP配置
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

域名解析配好
在这里插入图片描述

Nginx指令

[root@VM_0_3_centos ~]# cd /usr/local/nginx/sbin/
# nginx配置文件是否有错 
[root@VM_0_3_centos sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# nginx重启服务
[root@VM_0_3_centos sbin]# ./nginx -s reload

到此已经配置好,可直接使用域名登录相应的项目

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值