Linux nginx域名绑定方法(转)

本文详细介绍了如何在阿里云环境下使用Nginx为网站添加额外的域名绑定,包括定位配置文件、修改server_name指令、重启Nginx服务等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    转载的地方:http://www.stourweb.com/help/show/759.html

    以下配置的路径以阿里云提供的标准环境路径为准,如果您另行安装,请根据实际安装路径去找到您的配置文件进行配置。

    假如我们需要在我们的网站www.test.com上增加绑定一个m.test.com和一个test.com的域名,请进行如下类似的操作:

 

1、  cd /alidata/server/nginx/conf/vhosts/ 找到您的网站配置文件,一般是您的域名.conf,例如域名是:www.test.com,那就应该是www.test.com.conf

-------------------------------------------------------------------------------------------------------------------------------------

2、  vim www.test.com.conf  修改这个配置文件,您应该会看到如下类似的配置内容:

server {

        listen       80;

        server_name www.test.com;

        root /www/web/www_test_com/public_html;

        index index.php;

        error_page  400 /errpage/400.html;

        error_page  403 /errpage/403.html;

        error_page  404 /errpage/404.html;

 

        location ~ \.php$ {

                proxy_pass http://127.0.0.1:88;

                include naproxy.conf;

        }

        location / {

                try_files $uri @apache;

        }

        location @apache {

                 proxy_pass http://127.0.0.1:88;

                 include naproxy.conf;

        }

 

        access_log  /www/web_logs/www.test.com_access.log  wwwlogs;

        error_log  /www/web_logs/www.test.com_error.log;

}

-------------------------------------------------------------------------------------------------------------------------------------

3、  点击字母“i”开始编辑文件,输入内容:

server {

        listen       80;

        server_name www.test.com test.com m.test.com;

        root /www/web/www_test_com/public_html;

        index index.php;

        error_page  400 /errpage/400.html;

        error_page  403 /errpage/403.html;

        error_page  404 /errpage/404.html;

 

        location ~ \.php$ {

                proxy_pass http://127.0.0.1:88;

                include naproxy.conf;

        }

        location / {

                try_files $uri @apache;

        }

        location @apache {

                 proxy_pass http://127.0.0.1:88;

                 include naproxy.conf;

        }

 

        access_log  /www/web_logs/www.test.com_access.log  wwwlogs;

        error_log  /www/web_logs/www.test.com_error.log;

}

-------------------------------------------------------------------------------------------------------------------------------------

其中:

ServerName www.test.com test.com m.test.com;绑定的网站域名(您如果有多个域名添加在这里)

index index.php; 设置默认首页

root /www/web/www_test_com/public_html; 是指定网站的目录。

 

按“esc”退出编辑模式,输入“:wq”保存退出。

-------------------------------------------------------------------------------------------------------------------------------------

4、  输入命令:nginx –s reload 重启nginx测试。

-------------------------------------------------------------------------------------------------------------------------------------

5.  测试网站。请在浏览器中输入域名,测试设置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值