域名访问博客流程

Posted by Solejay on Tue, Dec 10, 2024

博客静态文件传到服务器

1# 创建同步目录
2mkdir /var/www/blog
3
4# 使用 rsync 方式同步
5cd BLOG_FOLDER # 本地
6rsync -avuz --progress --delete public/ root@ip:/var/www/blog

域名转发

当前域名基于腾讯云申请管理

我的域名

  1. 解析域名

  1. 配置为服务器 IP 地址

  1. 等待 DNS 刷新,根据域名请求

反向代理

Nginx 配置

安装

参考 VPS初始化配置 安装 Nginx

HTTP 转发配置

  1. 备份配置文件 cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
  2. 编辑配置文件 vim /etc/nginx/nginx.conf
 1user  nginx; # nginx 用户
 2worker_processes  auto;
 3error_log  /var/log/nginx/error.log notice;
 4pid        /var/run/nginx.pid;
 5events {
 6    worker_connections  1024;
 7}
 8http {
 9    include       /etc/nginx/mime.types;
10    default_type  application/octet-stream;
11    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
12                      '$status $body_bytes_sent "$http_referer" '
13                      '"$http_user_agent" "$http_x_forwarded_for"';
14    access_log  /var/log/nginx/access.log  main;
15    sendfile        on;
16    #tcp_nopush     on;
17    keepalive_timeout  65;
18    #gzip  on;
19    include /etc/nginx/conf.d/*.conf;
20    server {
21        # 配置 80访问端口
22        listen       80 default_server;
23        listen       [::]:80 default_server;
24
25        # 要配置的第三个地方,域名
26        # server_name www.sulvblog.cn;
27        # rewrite ^(.*) https://$server_name$1 permanent; #自动从http跳转到https
28        # 配置目录
29        root /var/www/blog;
30
31        include /etc/nginx/default.d/*.conf;
32
33        # 配置根目录
34        location / {
35            root /var/www/blog;
36            index  index.html index.htm;
37        }
38
39        # 配置 404 目录
40        error_page 404 /404.html;
41        location = /40x.html {
42            root   /var/www/blog;
43        }
44
45        error_page 500 502 503 504 /50x.html;
46            location = /50x.html {
47        }
48    }
49}
  1. nginx 用户分配权限
1sudo chown -R nginx:nginx /var/www/blog  # 或者 www-data:www-data,取决于你的 Nginx 用户
2sudo chmod -R 755 /var/www/blog
3
4sudo systemctl restart nginx

HTTPS 配置

  1. 申请 Let’s Encrypt 免费 SSL 证书
1sudo apt install certbot python3-certbot-nginx # 安装 Certbot
2
3sudo certbot --nginx -d solejay.cn -d www.solejay.cn
  1. 发现自动添加了 HTTPS的配置
 1    server {
 2        # rewrite ^(.*) https://$server_name$1 permanent; #自动从http跳转到https
 3        root /var/www/blog;
 4        include /etc/nginx/default.d/*.conf;
 5        location / {
 6            root /var/www/blog;
 7            index  index.html index.htm;
 8        }
 9        error_page 404 /404.html;
10        location = /40x.html {
11            root   /var/www/blog;
12        }
13        error_page 500 502 503 504 /50x.html;
14            location = /50x.html {
15        }
16        server_name www.solejay.cn solejay.cn; # managed by Certbot
17        listen [::]:443 ssl ipv6only=on; # managed by Certbot
18        listen 443 ssl; # managed by Certbot
19        ssl_certificate /etc/letsencrypt/live/solejay.cn/fullchain.pem; # managed by Certbot
20        ssl_certificate_key /etc/letsencrypt/live/solejay.cn/privkey.pem; # managed by Certbot
21        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
22        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
23    }
24
25    server {
26        if ($host = www.solejay.cn) {
27            return 301 https://$host$request_uri;
28        } # managed by Certbot
29
30
31        if ($host = solejay.cn) {
32            return 301 https://$host$request_uri;
33        } # managed by Certbot
34
35
36        listen       80 ;
37        listen       [::]:80 ;
38        server_name www.solejay.cn solejay.cn;
39        return 404; # managed by Certbot
40    }

Openresty 配置

基于 1panel 面板配置

  1. 创建网站

配置示例

  1. 静态文件上传到目录,修改用户组权限

  1. 访问域名

  2. 配置 https

    1. 申请证书

    1. 配置证书

    1. 验证 https 登录

搜索引擎收录

Google

Google Search Console

  1. 输入域名

  2. 在 DNS 服务商配置域名解析

腾讯云配置为例

  1. 验证是否成功

百度

添加网站地址

辣鸡百度,不好配置,放弃