美文网首页
Nginx 别名和跳转

Nginx 别名和跳转

作者: DB哥 | 来源:发表于2019-09-29 08:34 被阅读0次

    Linux系统环境

    [root@nginx01 ~]# cat /etc/redhat-release                     #==》系统版本
    CentOS release 6.7 (Final)
    [root@nginx01 ~]# uname –r                                   #==》内核版本
    2.6.32-573.el6.x86_64
    [root@nginx01 ~]# uname -m                                   #==》系统架构
    x86_64
    [root@nginx01 ~]# echo $LANG                                 #==》系统字符集
    en_US.UTF-8
    [root@nginx01 conf]# /application/nginx/sbin/nginx –v       #==》Nginx版本
    nginx version: nginx/1.16.0
    

    一、Nginx 别名配置

    标注:访问testwebsitecom跳转到http://www.testwebsite.com首页

    [root@nginx01 conf]# vim nginx.conf
     server {
     listen 80;
          server_name www.testwebsite.com testwebsite.com;
     location / {
     root html/www;
    
     index index.html index.htm;
     }
    
     error_page 500 502 503 504 /www/50x.html;
     location = /www/50x.html {
     root html;
     }
    
    }
    
    [root@nginx01 conf]# /application/nginx/sbin/nginx –t #==》检查Nginx语法
    nginx: the configuration file /application/nginx1.6.2/conf/nginx.conf syntax is ok
    nginx: configuration file /application/nginx1.6.2/conf/nginx.conf test is successful
    [root@nginx01 conf]# /application/nginx/sbin/nginx -s reload #==》平滑重启Nginx
    

    二、Nginx 跳转到指定网页

    [root@nginx01 conf]# vim nginx.conf
     server {
     listen 80;
     server_name testwebsite.com;
     rewrite ^/(.*) http://www.testwebsite.com/$1 permanent;
     }
    
     server {
     listen 80;
     server_name www.testwebsite.com;
     location / {
     root html/www;
     index index.html index.htm;
     }
    
     error_page 500 502 503 504 /www/50x.html;
     location = /www/50x.html {
     root html;
     }
    
    }
    [root@nginx01 conf]# /application/nginx/sbin/nginx –t #==》检查Nginx语法
    nginx: the configuration file /application/nginx1.6.2/conf/nginx.conf syntax is ok
    nginx: configuration file /application/nginx1.6.2/conf/nginx.conf test is successful
    [root@nginx01 conf]# /application/nginx/sbin/nginx -s reload #==》平滑重启Nginx
    

    三、Nginx 设置完整域名访问,其它访问转到无效页面

    [root@nginx01 conf]# vim nginx.conf
     server {
     listen 80;
     location / {
     deny all;
     }
    
     }
     server {
     listen 80;
     server_name www.testwebsite.com;
     location / {
     root html/www;
     index index.html index.htm;
     }
    
     error_page 500 502 503 504 /www/50x.html;
     location = /www/50x.html {
     root html;
     }
    
    }
    [root@nginx01 conf]# /application/nginx/sbin/nginx –t #==》检查Nginx语法
    nginx: the configuration file /application/nginx1.6.2/conf/nginx.conf syntax is ok
    nginx: configuration file /application/nginx1.6.2/conf/nginx.conf test is successful
    [root@nginx01 conf]# /application/nginx/sbin/nginx -s reload #==》平滑重启Nginx
    

    相关文章

      网友评论

          本文标题:Nginx 别名和跳转

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