nginx 二级域名,amh怎么nginx配置二级域名

阅读(117)发布于 2023-09-25

此时,我们新建一个/sites-enabled文件夹,并在其中添加blog.***.com.conf文件 [root@iZ2844brz0xZconf]#mkdirsites-enabled[root@iZ2844brz0xZsites-enabled]#vimblog.***.com.conf 在文件中添加 server{listen80;#监听端口server_nameblog.***.com;#绑定域名root/usr/local/nginx/html/blog/;#网站根目录,建议使用绝对路径indexindex.phpindex.htmlindex.htm;#默认文件#添加对php的解析location~\.php${fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;include/usr/local/nginx/conf/fastcgi_params;}#添加错误页面,利于搜索引擎收录以及良好的用户体验error_page404/404.html;location/404.html{root/usr/local/nginx/html/;}error_page500502503504/50x.html;location=/50x.html{ root/usr/local/nginx/html/;}} 内容可自行添加 Nginx单文件配置二级子域名 在nginx.conf文件的server模块中添加以下语句 if($host~*(\b(?!可以看到,我们的nginx配置文件分为: amh怎么nginx配置二级域名 一、新建rewrite规则,复制下面的规则然后另存为wp2.conf location/wordpress/{ if{ rewrite(.*)$1/index.htmlbreak; } if{ rewrite(.*)$1/index.php; } if(!

配图

之前在v2看到毒鸡汤,很是喜欢,想着也部署到我的博客上来,域名就用二级域名dujitang.flywill.cn,由于我的服务器是Nginx,于是就有了这篇配置二级域名的文章。

先谷歌了一下,得到的结果

这里用的是单文件配置的,很明显,这样不优雅。

我使用的是多文件配置,先看下配置文件

在http结构中include/etc/nginx/conf.d/*.conf;已经引入了该文件夹下所有以.conf文件结尾的文件

所以你要做的就是在该目录下建立新的二级域名的配置文件

然后重启nginx就搞定了。

新的配置文件只需要有server级就行了,其他诸如http、event在主配置文件中写就可以了。

具体可以点击这里查看。

Nginx多文件配置二级子域名(推荐)

首先,在自己的域名控制台中添加解析,这里以添加blog前缀为例

我用的是万网,在解析设置中添加解析

主机记录:你想要的二级域名

记录值:你的IP地址

保存后,我们就完成了第一步把子域名解析到我们的服务器上。

第二步:添加配置文件

进入nginx的/conf配置文件夹中,编辑nginx.conf文件

[root@iZ2844brz0xZ~]#cd/usr/local/nginx/conf/[root@iZ2844brz0xZ~]#vimnginx.conf

在http模块中添加如下语句

include/usr/local/nginx/conf/sites-enabled/*.conf;

告诉这个配置文件要去包含/sites-enabled目录下的所有以.conf结尾的配置文件。:wq保存。

此时,我们新建一个/sites-enabled文件夹,并在其中添加blog.***.com.conf文件

[root@iZ2844brz0xZconf]#mkdirsites-enabled[root@iZ2844brz0xZsites-enabled]#vimblog.***.com.conf

在文件中添加

server{listen80;#监听端口server_nameblog.***.com;#绑定域名root/usr/local/nginx/html/blog/;#网站根目录,建议使用绝对路径indexindex.phpindex.htmlindex.htm;#默认文件#添加对php的解析location~\.php${fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;include/usr/local/nginx/conf/fastcgi_params;}#添加错误页面,利于搜索引擎收录以及良好的用户体验error_page404/404.html;location/404.html{root/usr/local/nginx/html/;}error_page500502503504/50x.html;location=/50x.html{

root/usr/local/nginx/html/;}}

内容可自行添加

Nginx单文件配置二级子域名

在nginx.conf文件的server模块中添加以下语句

if($host~*(\b(?!www\b)\w+)\.\w+\.\w+){set$subdomain/$1;}location/{roothtml$subdomain;indexindex.htmlindex.phpindex.htmindex;}

即可解析到对应文件夹

最后,重启nginx即可

[root@iZ2844brz0xZsites-enabled]#/usr/local/nginx/sbin/nginx-sreload

来自:https://blog.csdn.net/LBinin/article/details/70188752

前提条件:

1)nginx已安装完毕;

2)php安装完毕;

NGINX配置详解(基础版)

这里为什么说是基础版,因为你简单的配置完下面的东西,你就完成了通过域名(可以多个)到服务器的工作了。你可以直接把原本nginx.cof里的server下的内容整个删掉,替换成我下面的server配置,然后自己倒腾一下,就可以用了!

可以看到,我们的nginx配置文件分为:

一、新建rewrite规则,复制下面的规则然后另存为wp2.conf

location/wordpress/{

if(-f$request_filename/index.html){

rewrite(.*)$1/index.htmlbreak;

}

if(-f$request_filename/index.php){

rewrite(.*)$1/index.php;

}

if(!-f$request_filename){

rewrite(.*)/wordpress/index.php;

}

}

二、注意上面的wordpress目录,假设你的二级目录或为blog则将上面两处修改为blog

三、将创建的wp2.conf存放至服务器/usr/local/nginx/conf/rewrite目录中

三、打开/usr/local/nginx/conf/vhost目录,找到网站的配置文件,比如小z博客的是xiaoz.me.conf在server{}引入新增的wp2.conf文件includerewrite/wp2.conf;保存并覆盖,如果怕改错,建议先备份。

四、最后重启nginx服务器,amhnginxrestart

以上就是关于nginx 二级域名的解答,如果对你有帮助,不妨关注本站,本站将为你整理更多内容。