博客部署到云服务器

Ikko Lv3

购买云服务器

安全组中把ssh,hhtp等的端口都打开

vscode连接

下载ssh插件
加击加号
输入ssh root@ip
输入密码
示例

配置环境

sudo yum update
安装 Nginx:
sudo yum install nginx
启动 Nginx 服务:
安装完成后,使用以下命令启动 Nginx 服务,并设置其开机自启动:
sudo systemctl start nginx
sudo systemctl enable nginx
配置 Nginx:
Nginx 的主要配置文件位于 /etc/nginx/nginx.conf。点击vscode的打开文件夹可以直接打开etc文件夹进行修改
如果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sudo systemctl start nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
[root@iZf8zb12gzozarzd9v5jloZ etc]# systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2023-09-20 16:58:30 CST; 6s ago
Process: 61954 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
Process: 61952 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 61950 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Sep 20 16:58:29 iZf8zb12gzozarzd9v5jloZ nginx[61954]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 20 16:58:29 iZf8zb12gzozarzd9v5jloZ nginx[61954]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Sep 20 16:58:29 iZf8zb12gzozarzd9v5jloZ nginx[61954]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 20 16:58:29 iZf8zb12gzozarzd9v5jloZ nginx[61954]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Sep 20 16:58:30 iZf8zb12gzozarzd9v5jloZ nginx[61954]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 20 16:58:30 iZf8zb12gzozarzd9v5jloZ nginx[61954]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Sep 20 16:58:30 iZf8zb12gzozarzd9v5jloZ nginx[61954]: nginx: [emerg] still could not bind()
Sep 20 16:58:30 iZf8zb12gzozarzd9v5jloZ systemd[1]: nginx.service: Control process exited, code=exited status=1
Sep 20 16:58:30 iZf8zb12gzozarzd9v5jloZ systemd[1]: nginx.service: Failed with result 'exit-code'.
Sep 20 16:58:30 iZf8zb12gzozarzd9v5jloZ systemd[1]: Failed to start The nginx HTTP and reverse proxy server.

sudo fuser -k 80/tcp

上传静态文件

这里我没有使用git,因为我和朋友共用一个服务器,所以我直接使用了winscp,将静态文件上传到服务器
scp

配置 Nginx

Nginx 的主要配置文件位于 /etc/nginx/nginx.conf。点击vscode的打开文件夹可以直接打开etc文件夹进行修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
server {
listen 80;
listen [::]:80;
server_name ikko-debug.love;
root /usr/xyc/ikko-debug.github.io-main;

# Load configuration files for the default server block.
#include /etc/nginx/default.d/*.conf;
index index.html index.htm;
error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

server_name可以是自己的域名(需要提前绑定)或者ip
检查配置并重新加载 Nginx:
检查 Nginx 配置是否有语法错误:
sudo nginx -t
如果没有错误,重新加载 Nginx 配置以使更改生效:
sudo systemctl reload nginx

  • Title: 博客部署到云服务器
  • Author: Ikko
  • Created at : 2023-07-27 14:29:01
  • Updated at : 2023-09-20 17:07:08
  • Link: https://redefine.ohevan.com/2023/07/27/博客部署到云服务器/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments