美文网首页
Linux 下nginx 配置/绑定域名

Linux 下nginx 配置/绑定域名

作者: Hi小胡 | 来源:发表于2019-03-06 10:46 被阅读2次

1. 配置文件(/etc/nginx/conf.d/**.conf)

  • 为每一个域名建立一个单独的配置文件时输入以下内容:
server
{
    listen   80;                            #监听端口设为 80。
    server_name  www.hlz.space;         #绑定您的域名。
    index index.htm index.html index.php;   #指定默认文件。
    root /var/www/html/hlzspace;           #指定网站根目录。
    include location.conf;                  #当您需要调用其他配置文件时才粘贴此项,如无需要,请删除此项。
}
  • 将多个域名规则写进一个共同的配置文件时输入以下内容:
server
{
    listen   80;                            #监听端口设为 80。
    server_name  www.hlz.space;         #绑定您的域名。
    index index.htm index.html index.php;   #指定默认文件。
    root /var/www/html/hlzspace;           #指定网站根目录。
    include location.conf;                  #当您需要调用其他配置文件时才粘贴此项,如无需要,请删除此项。
}
server
{
    listen   80;                            #监听端口设为 80。
    server_name  www.hlz2.space;         #绑定您的域名。
    index index.htm index.html index.php;   #指定默认文件。
    root /var/www/html/hlz2space;           #指定网站根目录。
    include location.conf;                  #当您需要调用其他配置文件时才粘贴此项,如无需要,请删除此项。
}
  • 为无 WWW 前缀的域名配置规则并加 301 跳转时输入以下内容:
server
{
    listen 80;
    server_name hlz.space;
    rewrite ^/(.*) http://www.hlz.space/$1 permanent;
}
  • 需要为域名添加 404 提示时输入以下内容:
server
{
    listen   80;                            #监听端口设为 80。
    server_name  www.hlz.space;         #绑定您的域名。
    index index.htm index.html index.php;   #指定默认文件。
    root /var/www/html/hlzspace;           #指定网站根目录。
    include location.conf;                  #当您需要调用其他配置文件时才粘贴此项,如无需要,请删除此项。
    error_page 404              #/404.html;
}

2. 重启nginx

$ service nginx  restart

相关文章

网友评论

      本文标题:Linux 下nginx 配置/绑定域名

      本文链接:https://www.haomeiwen.com/subject/qbttpqtx.html