2023-12-07 ·其他·云服务

阿里云学习笔记 2023再出发

买了99一年的阿里云服务器,记录操作过程。

ssh

生成ssh key

ssh-keygen -m PEM -t rsa -b 4096
ssh-keygen -m PEM -t rsa -b 4096

authorized_keys

~/.ssh/id_rsa.pub的内容复制到~/.ssh/authorized_keys

私钥

~/.ssh/id_rsa中,复制到Github中

部署

nginx

apt update
apt install nginx
systemctl status nginx # 查看状态
curl localhost # Welcome to nginx!

vim /etc/nginx/nginx.conf
apt update
apt install nginx
systemctl status nginx # 查看状态
curl localhost # Welcome to nginx!

vim /etc/nginx/nginx.conf

找到http块,并在该块内添加以下内容:

server {
    listen 80;
    server_name cn.wiidede.space;

    location / {
        root /var/www/cn.wiidede.space;
        try_files $uri $uri/ /index.html;
    }
}
server {
    listen 80;
    server_name cn.wiidede.space;

    location / {
        root /var/www/cn.wiidede.space;
        try_files $uri $uri/ /index.html;
    }
}
nginx -t # 检查配置
systemctl reload nginx
nginx -t # 检查配置
systemctl reload nginx

配置安全组策略

打开 80 443 端口

配置dns

A 记录

https

http {
  server {
    listen 443 ssl;
    server_name cn.wiidede.space;

    ssl_certificate /etc/nginx/ssl/cn.wiidede.space.pem;
    ssl_certificate_key /etc/nginx/ssl/cn.wiidede.space.key;

      location / {
          root /var/www/cn.wiidede.space;
          try_files $uri $uri/ /index.html;
      }
  }
}
http {
  server {
    listen 443 ssl;
    server_name cn.wiidede.space;

    ssl_certificate /etc/nginx/ssl/cn.wiidede.space.pem;
    ssl_certificate_key /etc/nginx/ssl/cn.wiidede.space.key;

      location / {
          root /var/www/cn.wiidede.space;
          try_files $uri $uri/ /index.html;
      }
  }
}

解析不同域名,解析不同路径,转发本地端口

  server {
    listen 80;
    server_name ~^(?:cn\.)?wiidede\.space$;

    location / {
      root /var/www/cn.wiidede.space;
      try_files $uri.html $uri $uri/ /index.html;
    }
  }

  server {
    listen 80;
    server_name sub.wiidede.space;

    location / {
      proxy_pass http://localhost:21001;
      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;
    }
  }

  server {
    listen 443 ssl;
    server_name wiidede.space;

    ssl_certificate /etc/nginx/ssl/wiidede.space.pem;
    ssl_certificate_key /etc/nginx/ssl/wiidede.space.key;

      location / {
          root /var/www/cn.wiidede.space;
          try_files $uri.html $uri $uri/ /index.html;
      }

      location /img {
          alias /var/www/img;
      }
  }

  server {
    listen 443 ssl;
    server_name cn.wiidede.space;

    ssl_certificate /etc/nginx/ssl/cn.wiidede.space.pem;
    ssl_certificate_key /etc/nginx/ssl/cn.wiidede.space.key;

      location / {
          root /var/www/cn.wiidede.space;
          try_files $uri.html $uri $uri/ /index.html;
      }
  }
  server {
    listen 80;
    server_name ~^(?:cn\.)?wiidede\.space$;

    location / {
      root /var/www/cn.wiidede.space;
      try_files $uri.html $uri $uri/ /index.html;
    }
  }

  server {
    listen 80;
    server_name sub.wiidede.space;

    location / {
      proxy_pass http://localhost:21001;
      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;
    }
  }

  server {
    listen 443 ssl;
    server_name wiidede.space;

    ssl_certificate /etc/nginx/ssl/wiidede.space.pem;
    ssl_certificate_key /etc/nginx/ssl/wiidede.space.key;

      location / {
          root /var/www/cn.wiidede.space;
          try_files $uri.html $uri $uri/ /index.html;
      }

      location /img {
          alias /var/www/img;
      }
  }

  server {
    listen 443 ssl;
    server_name cn.wiidede.space;

    ssl_certificate /etc/nginx/ssl/cn.wiidede.space.pem;
    ssl_certificate_key /etc/nginx/ssl/cn.wiidede.space.key;

      location / {
          root /var/www/cn.wiidede.space;
          try_files $uri.html $uri $uri/ /index.html;
      }
  }

docker

docker compose up -d


返回