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

  1. [root@localhost ~]# find / -name nginx.conf ##查找这个默认配置文件目录
  2. /etc/nginx/nginx.conf
  3. [root@localhost ~]#

Nginx加载的就是这个配置文件内的内容,下面附nginx.conf的内容

  1. user nginx;
  2. worker_processes auto;
  3.  
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7.  
  8. #pid logs/nginx.pid;
  9. worker_rlimit_nofile ;
  10.  
  11. events {
  12. worker_connections ;
  13. }
  14.  
  15. http {
  16. include mime.types;
  17. default_type application/octet-stream;
  18.  
  19. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  20. '$status $body_bytes_sent "$http_referer" '
  21. '"$http_user_agent" "$http_x_forwarded_for"';
  22.  
  23. access_log logs/access.log main;
  24.  
  25. sendfile on;
  26. tcp_nopush on;
  27.  
  28. #keepalive_timeout ;
  29. keepalive_timeout ;
  30.  
  31. #gzip on;
  32.  
  33. server {
  34. listen ;
  35. server_name localhost;
  36.  
  37. #charset koi8-r;
  38.  
  39. #access_log logs/host.access.log main;
  40.  
  41. location / {
  42. root /home/www/html/;
  43. index index.php index.html index.htm;
  44. if (!-e $request_filename) {
  45. rewrite ^(.*)$ /index.php?s=$ last;
  46. }
  47. }
  48.  
  49. #error_page /.html;
  50.  
  51. # redirect server error pages to the static page /50x.html
  52. #
  53. #error_page /50x.html;
  54.  
  55. # proxy the PHP scripts to Apache listening on 127.0.0.1:
  56. #
  57. #location ~ \.php$ {
  58. # proxy_pass http://127.0.0.1;
  59. #}
  60.  
  61. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
  62. #
  63.  
  64. location ~ ^.+\.php {
  65. root /home/www/html/;
  66. fastcgi_pass 127.0.0.1:;
  67. fastcgi_index index.php;
  68. fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
  69. fastcgi_param PATH_INFO $fastcgi_path_info;
  70. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  71. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  72. include fastcgi_params;
  73. }
  74.  
  75. # deny access to .htaccess files, if Apache's document root
  76. # concurs with nginx's one
  77. #
  78. #location ~ /\.ht {
  79. # deny all;
  80. #}
  81. }
  82.  
  83. # another virtual host using mix of IP-, name-, and port-based configuration
  84. #
  85. #server {
  86. # listen ;
  87. # listen somename:;
  88. # server_name somename alias another.alias;
  89.  
  90. # location / {
  91. # root html;
  92. # index index.html index.htm;
  93. # }
  94. #}
  95.  
  96. # HTTPS server
  97. #
  98. #server {
  99. # listen ssl;
  100. # server_name localhost;
  101.  
  102. # ssl_certificate cert.pem;
  103. # ssl_certificate_key cert.key;
  104.  
  105. # ssl_session_cache shared:SSL:1m;
  106. # ssl_session_timeout 5m;
  107.  
  108. # ssl_ciphers HIGH:!aNULL:!MD5;
  109. # ssl_prefer_server_ciphers on;
  110.  
  111. # location / {
  112. # root html;
  113. # index index.html index.htm;
  114. # }
  115. #}
  116.  
  117. }

nginx.conf

需要配置多个域名为方便管理。我指定这个nginx.conf加载指定配置文件*.conf

下面附我修改后的nginx.conf,记得先cp nginx.conf nginx.old.conf备份

  1. user nginx;
  2. worker_processes auto;
  3.  
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7.  
  8. #pid logs/nginx.pid;
  9. worker_rlimit_nofile ;
  10.  
  11. events {
  12. worker_connections ;
  13. }
  14.  
  15. http {
  16. include mime.types;
  17. default_type application/octet-stream;
  18.  
  19. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  20. '$status $body_bytes_sent "$http_referer" '
  21. '"$http_user_agent" "$http_x_forwarded_for"';
  22.  
  23. access_log logs/access.log main;
  24.  
  25. sendfile on;
  26. tcp_nopush on;
  27.  
  28. keepalive_timeout ;
  29.  
  30. gzip on;
  31.  
  32. # server {
  33. # listen default;
  34. # server_name _;
  35. # server_name ~.*;
  36. # return ;
  37. # }
  38.  
  39. include /etc/nginx/conf.d/*.conf; ###加载这个位置的.conf文件
  40. }

nginx.conf

其实就是删除了默认一些配置,让这个配置文件指定加载我指定文件夹的*.conf

目录/etc/nginx/conf.d下

新建一个配置文件

  1. vi /etc/nginx/conf.d/default.conf

下面附default.conf的配置文件内容

  1. server{
  2. listen ; #监听的端口号
  3. server_name www.youdomain.com; #您的域名
  4. location / {
  5. root /home/www/www.youdomain.com; #站点的路径
  6. index index.php index.html index.htm;
  7. if (!-e $request_filename) {
  8. rewrite ^(.*)$ /index.php$ last;
  9. }
  10. }
  11. location ~ ^.+\.php {
  12. root /home/www.youdomain.com; #站点的路径
  13. fastcgi_pass 127.0.0.1:; #根据自己的 php-fpm 配置填写
  14. fastcgi_index index.php;
  15. ###配置支持pathinfo
  16. fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
  17. fastcgi_param PATH_INFO $fastcgi_path_info;
  18. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  19. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  20. include fastcgi_params;
  21. }
  22. }
  23.  
  24. server{
  25. listen ; #监听的端口号
  26. server_name bbs.yourdomain.com; #您的域名
  27. location / {
  28. root /home/www/bbs.yourdomain.com; #站点的路径
  29. index index.php index.html index.htm;
  30. if (!-e $request_filename) {
  31. rewrite ^(.*)$ /index.php$ last;
  32. }
  33. }
  34. location ~ ^.+\.php {
  35. root /home/www/bbs.yourdomain.com; #站点的路径
  36. fastcgi_pass 127.0.0.1:; #根据自己的 php-fpm 配置填写
  37. fastcgi_index index.php;
  38. ###配置支持pathinfo
  39. fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
  40. fastcgi_param PATH_INFO $fastcgi_path_info;
  41. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  42. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  43. include fastcgi_params;
  44. }
  45. }

default.conf

保存退出后重启nginx即可

  1. 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设置绑定解析实现二级域名多域名的更多相关文章

  1. nginx设置不使用缓存 add_header Cache-Control no-cache

    nginx设置不使用缓存 server { listen 443; #域名 server_name www.dev.163.com; #字符集 charset utf-8; ssl on; ssl_c ...

  2. Thinkphp在nginx设置同域名二级目录访问

    Thinkphp在nginx设置同域名二级目录访问,是因为最近弄一个小程序项目,要https,但是只有单个域名,不能通配域名,所有只好用二级目录,thinkphp二级目录访问要怎么设置呢 下面是ngi ...

  3. nginx服务器绑定多个域名、支持pathinfo路由、隐藏index.php入口文件

    这篇文章仅仅是操作,解释说明部分待更新. 1. 修改nginx的配置文件(我的配置文件在/etc/nginx/nginx.conf) [root@xxx ~]# find / -name nginx. ...

  4. nginx 多域名配置 (nginx如何绑定多个域名)

         nginx绑定多个域名可又把多个域名规则写一个配置文件里,也可又分别建立多个域名配置文件,我一般为了管理方便,每个域名建一个文件,有些同类域名也可又写在一个总的配置文件里. 一.每个域名一个 ...

  5. 借助微软提供的url重写类库URLRewriter.dll(1.0)实现程序自动二级域名,域名需要泛解析

    二级域名和系统中会员帐号自动关联,也就是系统中注册一个会员,会员自动就可以通过二级域名来访问,比如我的帐号是zhangsan,我在morecoder.com注册后,访问zhangsan.morecod ...

  6. Prometheus使用nginx 设置二级路径反向代理

    1.nginx 设置 location /promethues/ { proxy_pass http://10.xx.xxx.55:9090/prometheus/; } 2.设置prometheus ...

  7. [C#]使用 C# 代码实现拓扑排序 dotNet Core WEB程序使用 Nginx反向代理 C#里面获得应用程序的当前路径 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法 .Net程序员 初学Ubuntu ,配置Nignix 夜深了,写了个JQuery的省市区三级级联效果

    [C#]使用 C# 代码实现拓扑排序   目录 0.参考资料 1.介绍 2.原理 3.实现 4.深度优先搜索实现 回到顶部 0.参考资料 尊重他人的劳动成果,贴上参考的资料地址,本文仅作学习记录之用. ...

  8. 设置泛域名和设置IIS下面不同网站通过不同域名公用80端口的操作指引

    原文链接: http://www.lookdaima.com/WebForms/WebPages/Blanks/Pm/Docs/DocItemDetail.aspx?id=4be204ca-249b- ...

  9. 思科E3200 路由器 DD-WRT 设置花生壳和3322.org动态域名(DDNS)

    花生壳设置(已測试) ddns.oray.com:80 username   aaaa password bbbb 主机名   abc.gicp.net URL       /ph/update?ho ...

随机推荐

  1. 从一个input点击引起的思考

    一个input或者select标签都是有属于自己的disabled属性的,这个属性很少被使用,但是我们在项目实际开发的过程中也会遇到,比如我选择之后就让他置灰不可以变动了,那么久可利用js动态设置.对 ...

  2. ViewPager中View的复用

    代码例如以下: public class MyViewPagerAdapter extends PagerAdapter { //显示的数据 private List<DataBean> ...

  3. SQL语句多表连接查询语法

    一.外连接 1.左连接  left join 或 left outer join SQL语句:select * from student left join score on student.Num= ...

  4. Chrome控制台命令

    window.print();打印当前窗口内容或输出为pdf

  5. ios4--UIView的常见属性(尺寸和位置)

    // // ViewController.m // 08-UIView的常见属性(尺寸和位置) // // frame:相对于父控件左上角定位 // bounds:改变长宽,左上角是相对于自己 // ...

  6. bzoj 3993 星际战争

    题目大意: X军团和Y军团正在激烈地作战  在战斗的某一阶段,Y军团一共派遣了N个巨型机器人进攻X军团的阵地,其中第i个巨型机器人的装甲值为Ai 当一个巨型机器人的装甲值减少到0或者以下时,这个巨型机 ...

  7. qtree4

    https://zybuluo.com/ysner/note/1236834 题面 给出一棵边带权的节点数量为\(n\)的树,初始树上所有节点都是白色.有两种操作: 改变节点\(x\)的颜色,即白变黑 ...

  8. Secure CRT中解决vim高亮设置的方法

    此文主要是解决vim编程中高亮显示的.原因是: 1.默认情况下,SecureCRT是有自己的终端显示颜色.这样在我们编程中不利于阅读内容. 2.我们必须到Linux系统中进行改进才能真正解决这样的问题 ...

  9. jquery插件开发基本步骤

    一.介绍 插件编写的目的是给已经有的一系列方法或函数做一个封装,以便在其他地方重复使用,方便后期维护. JQuery除了提供一个简单.有效的方式进行管理元素以及脚本,它还还提供了例外一种机制:即给核心 ...

  10. 湖南集训day3

    难度:☆☆☆☆☆☆☆ 此时相望不相闻,愿逐月华流照君 /* 23 233 223 啦啦啦德玛西亚 */ #include<iostream> #include<cstdio> ...