背景

只有一台云服务器,部署了自己写的后端管理系统,又需要部署下自己的个人博客平台,但是只有一个域名,想要合理的利用下二级域名。

域名配置

首先需要配置域名解析,讲需要添加的二级域名添加到现有的解析记录里:

  1. 各个平台操作类似,我的域名在西部数据买的,直接配置就好,截图显示如下:
  2. 服务器上配置安全策略打开对应端口:

服务器配置

  1. 阿里云安全组策略配置:



    2.服务器安装nginx,已安装略过

Nginx配置

  1. nginx现有配置:

    在conf下新增 hosts文件夹。【可自定义】

    #user  nobody;
    worker_processes 1;
    error_log logs/error.log;
    error_log logs/error.log notice;
    error_log logs/error.log info; events {
    worker_connections 1024;
    } http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    #tcp_nopush on; server {
    listen 80;
    server_name mount.pub;
    rewrite ^(.*)$ https://${server_name}$1 permanent; error_page 500 502 503 504 /50x.html;
    root /var/blog/dist/;
    }
    server {
    listen 443 ssl;
    server_name mount.pub;
    ssl on;
    # https证书
    ssl_certificate /usr/local/nginx/conf/cert/1_www.xxx.pub_bundle.crt;
    ssl_certificate_key /usr/local/nginx/conf/cert/2_www.xxx.pub.key;
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on; location / {
    root /var/blog/dist;
    index index.html index.htm;
    # 避免中文乱码
    charset utf-8,gbk;
    }
    location /app/ {
    proxy_pass https://127.0.0.1:8081;
    client_max_body_size 16m;
    client_body_buffer_size 128k;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Port $server_port;
    #跨域访问设置
    add_header Access-Control-Allow-Origin *;
    }
    }
    #二级域名 配置文件夹
    include hosts/*.conf;
    }
  2. 在hosts下新增二级域名的配置文件

    例如我需要加的:admin.mount.pub.conf

    配置如下:
server {
default_type 'text/html';
charset utf-8;
listen 80;
autoindex off;
server_name admin.mount.pub;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php; if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location / {
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
#二级域名对应的文件路径
root /var/www/dist/;
}
}`
  1. nginx配置生效

    reload配置
# /usr/local/nginx/ 是我的nginx安装路径
/usr/local/nginx/sbin/nginx -s reload

页面访问生效

效果如下

最新文章

  1. Java(一)
  2. C#获取本机公网IP
  3. .NET下Excel报表的打印
  4. socket 简介
  5. 设置 Eclipse 智能代码提示,大幅度减少 alt+/ 使用频率,打每个字都出现代码提示的办法
  6. hql查询技巧
  7. 台式电脑部署xen虚拟化的各种问题
  8. SQL Server 死锁检查
  9. 【多重背包模板】poj 1014
  10. iOS11、iPhone X、Xcode9 适配
  11. 无法连接MySQL
  12. Git版本控制 — 日常使用(二)
  13. 2017-9-11-Linux开机启动脚本
  14. 实验隐藏参数&quot;_allow_resetlogs_corruption&quot;的使用
  15. [datatable]排序时指定某列不可排序
  16. Redis----windows下的常用命令二
  17. sql server merge into 与update 批量更新1 百万测试数据的性能比较
  18. Spring.Net 入门学习(一)实现控制器翻转与依赖注入
  19. Python 调试:step into/step out/step over 的区别
  20. Ubuntu12.10下Python(cx_Oracle)访问Oracle解决方案

热门文章

  1. Django----初始化项目结构
  2. 使用 Jasypt 加密 Spring Boot 配置文件
  3. moviepy音视频剪辑:使用concatenate_videoclips和clips_array将多个视频合成一个顺序播放或同屏播放的视频
  4. 第15.6节 PyQt5安装与配置
  5. PyQt(Python+Qt)学习随笔:设定toolButton弹出菜单的方法
  6. sql绕过小技巧
  7. python安装Scrapy框架
  8. nginx学习之——虚拟主机配置
  9. Ajax相关基础知识总结
  10. 05-flask基础补充