博客
关于我
阿里云创建二级域名,并在在nginx中配置二级域名访问
阅读量:137 次
发布时间:2019-02-26

本文共 1222 字,大约阅读时间需要 4 分钟。

创建二级域名及Nginx配置指南

一、创建二级域名

在创建并配置二级域名之前,需先完成以下步骤:

  • 进入阿里云的域名管理界面

    访问阿里云管理平台,进入“域名管理”模块。

  • 新建二级域名

    在域名列表中,点击“新增解析”,填写所需的二级域名(如mp.xxx.cn),完成后保存。

  • 配置DNS解析

    确保新建的二级域名已正确解析到阿里云的服务器IP地址。

  • 验证域名访问

    在浏览器中输入二级域名地址(如http://mp.xxx.cn),确认访问无误。

  • 二、Nginx配置指南

    接下来,将二级域名配置到Nginx服务器中:

  • 安装Nginx(以CentOS7为例)

    • 添加Nginx源:
      sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    • 更新源并安装:
      yum search nginxyum install -y nginx
    • 启用并启动服务:
      sudo systemctl start nginx.servicesudo systemctl enable nginx.service
    • 常用命令:
      nginx -t # 测试配置systemctl is-enabled nginx.service # 查询服务状态
  • 配置Nginx服务器块

    /etc/nginx/conf.d目录下创建新的配置文件mp.xxx.cn.conf,内容如下:

    server {    listen 80;    server_name mp.xxx.cn;    # 静态文件托管    location / {        root /var/lib/jenkins/workspace/-admin/dist;        try_files $uri $uri/ /index.html;        index index.html index.htm;    }    # 前端路由处理    location @router {        rewrite ^.* /index.html last;    }    # API代理    location /api/v1 {        proxy_pass http://localhost:5000/api/v1;    }}
  • 加载配置文件

    使新的配置生效:

    sudo nginx -s reload
  • 注意事项

    • 域名解析:确保DNS记录已正确指向阿里云服务器IP地址。
    • 服务器权限:确认Nginx服务有权限访问静态文件目录/usr/share/nginx/html
    • 端口配置:如API服务运行于非标准端口(如5000),需在Nginx配置中相应设置。

    通过以上步骤,您已成功创建并配置二级域名及Nginx服务器,访问二级域名地址即可查看内容。

    转载地址:http://ijvf.baihongyu.com/

    你可能感兴趣的文章
    npm报错Failed at the node-sass@4.14.1 postinstall script
    查看>>
    npm报错fatal: Could not read from remote repository
    查看>>
    npm报错File to import not found or unreadable: @/assets/styles/global.scss.
    查看>>
    npm报错TypeError: this.getOptions is not a function
    查看>>
    npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
    查看>>
    npm淘宝镜像过期npm ERR! request to https://registry.npm.taobao.org/vuex failed, reason: certificate has ex
    查看>>
    npm版本过高问题
    查看>>
    npm的“--force“和“--legacy-peer-deps“参数
    查看>>
    npm的安装和更新---npm工作笔记002
    查看>>
    npm的常用操作---npm工作笔记003
    查看>>
    npm的常用配置项---npm工作笔记004
    查看>>
    npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
    查看>>
    npm编译报错You may need an additional loader to handle the result of these loaders
    查看>>
    npm设置淘宝镜像、升级等
    查看>>
    npm设置源地址,npm官方地址
    查看>>
    npm设置镜像如淘宝:http://npm.taobao.org/
    查看>>
    npm配置安装最新淘宝镜像,旧镜像会errror
    查看>>
    NPM酷库052:sax,按流解析XML
    查看>>
    npm错误 gyp错误 vs版本不对 msvs_version不兼容
    查看>>
    npm错误Error: Cannot find module ‘postcss-loader‘
    查看>>