nginx设置绑定解析实现二级域名多域名
apache(httpd)配置多个二级域名看这个链接:https://www.cnblogs.com/Crazy-Liu/p/10879928.html
网站的目录结构为
/home/www
├── bbs.yourdomain.com
└── www.yourdomain.com
html为nginx的安装目录下默认的存放源代码的路径。
bbs为论坛程序源代码路径
www为主页程序源代码路径
把相应程序放入上面的路径通过
http://www.youdomain.com 访问的就是主页
http://bbs.yourdomain.com 访问的就是论坛
其它二级域名类推。
前言:
现在很多人都会解析www二级域名作为主网站。可想弄个博客的网站呢,条件又只有一个ip一台服务器,可以使用nginx设置多个域名。
注意:nginx默认的配置文件是nginx.conf
[root@localhost ~]# find / -name nginx.conf ##查找这个默认配置文件目录
/etc/nginx/nginx.conf
[root@localhost ~]#
Nginx加载的就是这个配置文件内的内容,下面附nginx.conf的内容
user nginx;
worker_processes auto; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid;
worker_rlimit_nofile ; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on;
tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on; server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root /home/www/html/;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$ last;
}
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
#error_page /50x.html; # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
# location ~ ^.+\.php {
root /home/www/html/;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }
nginx.conf
需要配置多个域名为方便管理。我指定这个nginx.conf加载指定配置文件*.conf
下面附我修改后的nginx.conf,记得先cp nginx.conf nginx.old.conf备份
user nginx;
worker_processes auto; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid;
worker_rlimit_nofile ; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on;
tcp_nopush on; keepalive_timeout ; gzip on; # server {
# listen default;
# server_name _;
# server_name ~.*;
# return ;
# } include /etc/nginx/conf.d/*.conf; ###加载这个位置的.conf文件
}
nginx.conf
其实就是删除了默认一些配置,让这个配置文件指定加载我指定文件夹的*.conf
目录/etc/nginx/conf.d下
新建一个配置文件
vi /etc/nginx/conf.d/default.conf
下面附default.conf的配置文件内容
server{
listen ; #监听的端口号
server_name www.youdomain.com; #您的域名
location / {
root /home/www/www.youdomain.com; #站点的路径
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$ last;
}
}
location ~ ^.+\.php {
root /home/www.youdomain.com; #站点的路径
fastcgi_pass 127.0.0.1:; #根据自己的 php-fpm 配置填写
fastcgi_index index.php;
###配置支持pathinfo
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
} server{
listen ; #监听的端口号
server_name bbs.yourdomain.com; #您的域名
location / {
root /home/www/bbs.yourdomain.com; #站点的路径
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$ last;
}
}
location ~ ^.+\.php {
root /home/www/bbs.yourdomain.com; #站点的路径
fastcgi_pass 127.0.0.1:; #根据自己的 php-fpm 配置填写
fastcgi_index index.php;
###配置支持pathinfo
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
default.conf
保存退出后重启nginx即可
systemctl restart nginx.service
总结一下步骤就是
1.确认要增加的二级域名,如bbs.yourdomain.com换成你的域名后添加到你的default.conf配置文件
2.设置bbs.yourdomain.com解析到你的nginx服务器ip ###这个需要到你的域名供应商那里操作,就和解析www一样解析这个自定义的bbs。
4.在网站目录下(我这里是、home/www)创建bbs.yourdomain.com目录
5.把源码放入bbs.yourdomain.com目录
6.重新加载nginx配置
7.访问http://bbs.yourdomain.com
nginx设置绑定解析实现二级域名多域名的更多相关文章
- nginx设置不使用缓存 add_header Cache-Control no-cache
nginx设置不使用缓存 server { listen 443; #域名 server_name www.dev.163.com; #字符集 charset utf-8; ssl on; ssl_c ...
- Thinkphp在nginx设置同域名二级目录访问
Thinkphp在nginx设置同域名二级目录访问,是因为最近弄一个小程序项目,要https,但是只有单个域名,不能通配域名,所有只好用二级目录,thinkphp二级目录访问要怎么设置呢 下面是ngi ...
- nginx服务器绑定多个域名、支持pathinfo路由、隐藏index.php入口文件
这篇文章仅仅是操作,解释说明部分待更新. 1. 修改nginx的配置文件(我的配置文件在/etc/nginx/nginx.conf) [root@xxx ~]# find / -name nginx. ...
- nginx 多域名配置 (nginx如何绑定多个域名)
nginx绑定多个域名可又把多个域名规则写一个配置文件里,也可又分别建立多个域名配置文件,我一般为了管理方便,每个域名建一个文件,有些同类域名也可又写在一个总的配置文件里. 一.每个域名一个 ...
- 借助微软提供的url重写类库URLRewriter.dll(1.0)实现程序自动二级域名,域名需要泛解析
二级域名和系统中会员帐号自动关联,也就是系统中注册一个会员,会员自动就可以通过二级域名来访问,比如我的帐号是zhangsan,我在morecoder.com注册后,访问zhangsan.morecod ...
- Prometheus使用nginx 设置二级路径反向代理
1.nginx 设置 location /promethues/ { proxy_pass http://10.xx.xxx.55:9090/prometheus/; } 2.设置prometheus ...
- [C#]使用 C# 代码实现拓扑排序 dotNet Core WEB程序使用 Nginx反向代理 C#里面获得应用程序的当前路径 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法 .Net程序员 初学Ubuntu ,配置Nignix 夜深了,写了个JQuery的省市区三级级联效果
[C#]使用 C# 代码实现拓扑排序 目录 0.参考资料 1.介绍 2.原理 3.实现 4.深度优先搜索实现 回到顶部 0.参考资料 尊重他人的劳动成果,贴上参考的资料地址,本文仅作学习记录之用. ...
- 设置泛域名和设置IIS下面不同网站通过不同域名公用80端口的操作指引
原文链接: http://www.lookdaima.com/WebForms/WebPages/Blanks/Pm/Docs/DocItemDetail.aspx?id=4be204ca-249b- ...
- 思科E3200 路由器 DD-WRT 设置花生壳和3322.org动态域名(DDNS)
花生壳设置(已測试) ddns.oray.com:80 username aaaa password bbbb 主机名 abc.gicp.net URL /ph/update?ho ...
随机推荐
- autoconfig
實例:假設我們有個資料夾為d:\tmp和e:\tmp ,而我們只要將d:\tmp中有異動的檔案複製到e:\tmp下的話,用法如下xcopy d:\tmp\. e:\tmp\ /D /S /Y實例:如果 ...
- Cocos2d-html5入门之2048游戏
一.介绍 Cocos2d-JS是Cocos2d-x的Javascript版本,它的前身是Cocos2d-html5.在3.0版本以前叫做Cocos2d-html5,从3.0版本开始叫做Cocos2d- ...
- Ubuntu13.10添加/删除PPA
什么是ppa ppa即Personal Package Archive(个人安装包文档),简单来说就是一些个人或者团体通过独立的网站发布的第三方的软件源.将这些软件源添加到你的电脑上后,你就可以像使用 ...
- 并发与并行(concurrency vs parallesim)
最近对计算机中并发(concurrency)和并行(parallesim)这两个词的区别很迷惑,将搜索到的相关内容整理如下. http://www.vaikan.com/docs/Concurrenc ...
- Hybrid 开发
主讲人:吴彬 要学习某个东西之前,我们首先要了解这个东西是什么?然后我们要了解这东西有什么用,有什么好处和弊端?最后我们要知道这东西怎么用? 简单点就是 ——是什么?有什么用?怎么用? 那么进入正题 ...
- 在Struts2中ognl.MethodFailedExceptiond异常的解决办法
问题描述: 在 Struts2 里面,当页面向服务器提交参数时报ognl.MethodFailedException:和java.lang.NoSuchMethodException:异常 异常信息 ...
- 理解JavaScript中的闭包
(这篇文章后面关于onclick事件的解释是错误的,请不要被误导了2016.6.16) 闭包这个概念给JavaScript初学者心中留下了巨大的阴影,网络上关于闭包的文章不可谓不多,但是能让初学者看懂 ...
- [Apple开发者帐户帮助]九、参考(2)撤销特权
您可以撤消的证书取决于证书类型和您的角色.如果您是个人注册,则可以撤销所有类型的开发和分发证书,除非另有说明.组织团队的任何成员都可以撤销自己的开发证书,但只有帐户持有人或管理员可以撤销分发证书. 证 ...
- 阿拉伯数字1与英语字母l造成的代码bug
<img src="./images/demo3/1a.png" /> <img src="./images/demo3/la.png" /& ...
- 【转】关于Java基础你不得不会的34个问题
1. 面向对象和面向过程的区别 面向过程 优点: 性能比面向对象高,因为类调用时需要实例化,开销比较大,比较消耗资源;比如单片机.嵌入式开发.Linux/Unix等一般采用面向过程开发,性能是最重要的 ...