nginx泛域名解析实现二级域名多域名

2017-10-27服务器
125

利用nginx泛域名解析配置二级域名和多域名
 
网站的目录结构为
html
├── bbs
└── www
 
html为nginx的安装目录下默认的存放源代码的路径。
 
bbs为论坛程序源代码路径
www为主页程序源代码路径
 
把相应程序放入上面的路径通过
http://www.youdomain.com 访问的就是主页
http://bbs.yourdomain.com 访问的就是论坛
其它二级域名类推。
 
 server {
        listen       80;
        server_name  ~^(?<subdomain>.+).yourdomain.com$;
        root   html/$subdomain; 
        index  index.html index.htm index.php;
        fastcgi_intercept_errors on;
        error_page  404      = /404.html;
        location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't
                # break when using query string
                try_files $uri $uri/ =404;
       }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  domain $subdomain;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /.ht {
            deny  all;
        }
    }
总结一下步骤就是
 
1.把上面的红色配置换成你的域名后添加到你的nginx.conf配置文件
 
2.确认要增加的二级域名,如bbs.yourdomain.com
 
3.设置bbs.yourdomain.com解析到你的nginx服务器ip
 
4.在html目录下创建bbs目录
 
5.把源码放入bbs目录
 
6.重新加载nginx配置
 
kill -HUP cat /usr/local/lnmp/nginx/nginx.conf
 
(需要把上面命令的路径换成你的配置文件路径)
 
7.访问http://bbs.yourdomain.com
The End

相关推荐

Nginx强制http跳转https访问的几种方法
Nginx让http的链接自动跳转到https的链接,其实方法还是蛮多的,下面介绍两种常用方法。 方法一 可以把所有的HTTP请求通过rewrite重写到HTTPS上 server{ listen 80; server_name XXXXX.com; //你的域名 //rewrite ^(.*)$ https://XXXXXX.com permanent; rewri...
2023-06-19 服务器
372

Nginx使用中文文件名中文目录404错误的解决办法
一:确定你的系统是UTF编码 [root@Tserver ~]# env|grep LANG LANG=en_US.UTF-8 二:NGINX配置文件里默认编码设置为utf-8 server { listen 80; server_name .inginx.com ; index index.html index.htm index.php; root /usr/local/nginx/html/inginx.com; ch...
2022-10-14 服务器
902

nginx加载伪静态文件.htaccess的办法
很多网站需要采用伪静态来访问动态网页。所以像phpcms这样的系统,都提供了一个.htaccess文件,供写伪静态规则。但这个规则是针对Apache的。在nginx服务器上并不起作用。 nginx 可以直接将伪静态规则写在配置文件中,但这个需要有服务器管理权限,普通站长不...
2019-01-16 服务器
544

怎么让服务器iis6-7支持.apk文件下载
随着智能手机的普及,越来越多的人使用手机上网,很多网站也应手机上网的需要推出了网站客户端,.apk文件就是安卓(Android)的应用程序后缀名,默认情况下,使用IIS作为Web服务器的无法下载此文件,那么怎么才能让IIS支持.apk文件的下载呢? IIS服务器不能下...
2018-09-10 服务器
149

JRE的安装及环境变量配置
JRE(Java Runtime Environment,Java运行环境),运行JAVA程序所必须的环境的集合,包含JVM标准实现及Java核心类库。 下载解压,然后双击安装,跟普通安装程序一样。 安装完毕之后就是需要我们来设置环境变量了 假设jre安装目录为 C:\Program Files (x86)\J...
2018-04-18 服务器
2068

第三方登录 QQ互联 redirect uri is illegal(100010) 回调的解决方法
redirect uri is illegal(100010)错误怎么解决呢,我只是修改了下网站图标,然后回调地址修改了,因为之前是不带http://的,现在腾讯不加不行了,可加上后,网站就登录不上去了,咨询了客服,得到的回答是这样的: 100010报错解析方法:可以把出错页面的地址...
2018-04-07 服务器
238