Alibaba Cloud creates a second-level domain name and configures the second-level domain name access in nginx

1. Create a second-level domain name

  • 1. Click on the domain name on Alibaba Cloud (get another domain name provider)

Insert picture description here

  • 2. Click resolve in the domain name list

    Insert picture description here

  • 3. New analysis

    Insert picture description here

  • 4. Add a second-level domain name

    Insert picture description here

  • 5. After parsing the production, access the address in the browser normally

    # xxx是你的域名
    mp.xxx.cn
    

2. nginxConfigure your second-level domain name in

  • 1. I am a centosserver, use yuminstallation methodnginx

    • Add source

      # 默认情况Centos7中无Nginx的源,最近发现Nginx官网提供了Centos的源地址。因此可以如下执行命令添加源:
      
      sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
      
    • Check if the source is installed successfully

      yum search nginx
      
    • installation

      yum install -y nginx
      
    • Common commands

      sudo systemctl start nginx.service
      sudo systemctl enable nginx.service
      nginx -t # 检查配置项目
      systemctl is-enabled servicename.service #查询服务是否开机启动
      systemctl enable *.service #开机运行服务
      systemctl disable *.service #取消开机运行
      systemctl start *.service #启动服务
      systemctl stop *.service #停止服务
      systemctl restart *.service #重启服务
      systemctl reload *.service #重新加载服务配置文件
      systemctl status *.service #查询服务运行状态
      systemctl --failed #显示启动失败的服务
      
    • File Directory

      • 1. Static file directory/usr/share/nginx/html
      • 2. Configuration file directory/etc/nginx
  • 2. /etc/nginx/conf.dCreate a file in the directory

    # xxx是你的域名
    mp.xxx.conf
    
  • 3. Configure your conffiles

    server {
          
          
      listen 80;
      server_name 你的二级域名;
      # 配置静态文件
      location /{
          
                                                                                                              
        #default_type text/html;                  
        #return 200 'doc';          
        root /var/lib/jenkins/workspace/-admin/dist;
        try_files $uri $uri/ @router;
        index index.htm index.html;                                                                            
      }                                                                                                              
      location @router {
          
                                                                                                       
      	rewrite ^.*$ /index.html last; # 关键一句,处理前端项目vue,react刷新404问题                                                              
      } 
      # 配置接口
      location /api/v1 {
          
                                                                                                       
      	proxy_pass http://localhost:5000/api/v1;                                                               
      }      
    }
    

Guess you like

Origin blog.csdn.net/kuangshp128/article/details/108823585