当前位置:网站首页>利用阿里云国际购买的服务器搭建个人网站步骤
利用阿里云国际购买的服务器搭建个人网站步骤
2022-06-10 19:23:00 【87cloud】
在今天的帖子中,我将向您展示我如何在阿里云上部署我的网站 87cloud,com。
我在阿里云弹性计算服务(ECS)实例上使用WordPress构建了我的网站,具有Nginx,PHP 7.2,FastCGI,MariaDB和Redis缓存,以实现最佳性能。
在开始之前,我假设您已经对云、网络和 Linux 命令行知识有了基本的了解。
您还需要为您的网站提供一个功能域名。
步骤#1:创建新帐户
如果您还没有帐户,可以在此处注册。新用户可以享受价值300-1200美元的免费试用,有效期为2个月。如果您不确定如何执行此操作,请参阅本教程。
设置帐户后,您就可以部署高性能的WordPress网站了!
步骤 2:创建新的 ECS 实例
通过输入您的电子邮件和密码登录阿里云控制台。出于安全目的,您可能需要输入安全代码。
在阿里云控制台中,单击产品,然后从列表中选择弹性计算服务。
单击实例,然后从左上角的下拉菜单中选择您的区域。将显示可用区域的列表。
单击创建实例。对于我的实例,我选择了以下配置。
- 计费方式:订阅
- 实例类型:IO 优化
- vCPU: 1
- 内存: 4GB
- 家庭:平衡型 mn4
- 台数: 1 台
我选择了一个具有 4GB 物理内存 (RAM) 和 1 个虚拟 CPU 的 IO 优化型实例。如果您的网站将托管更多动态内容,请考虑购买更高规格的实例。
现在,您必须为实例选择合适的映像。我为我的服务器选择了一个Ubuntu 16.04映像。
- 镜像类型:公共镜像
- 操作系统 (OS):Ubuntu
- 操作系统版本: 16.04 64位
- 启用安全增强功能。此功能将添加一些安全功能,如后门检测,远程登录警报等。
还有其他一些配置需要考虑,我为其余配置选择了默认设置。
步骤#3:设置阿里云DNS
阿里云 DNS 是一项权威的高可用性和高度可扩展的域名解析和管理服务。DNS代表域名系统,它帮助我们将IP地址映射到域名。要使用阿里云的 DNS 服务,您需要在域的控制面板中更新名称服务器。域名服务器将由阿里云提供。
在开始之前,您需要获取我们实例的公有 IP。请按照以下步骤继续操作:
- 登录 ECS 管理控制台
- 单击实例
- 记下实例的公有 IP
- 登录阿里云控制台
- 单击产品列表中的 CloudDNS
- 单击“基本 DNS”
- 点击添加域名
- 输入您的域名,然后点击确认
将显示几个名称服务器。在网域的控制面板中更新它们。DNS 迁移可能需要长达 48 小时,因此您必须耐心等待!
现在,您必须添加两个“A”记录。
为第一条“A”记录输入以下详细信息。
- 记录类型: A
- 主机:@
- ISP 线路:默认
- 值:实例的 IP 地址
- TTL: 10 分钟
为其他“A”记录输入以下详细信息。
- 记录类型: A
- 主持人: *
- ISP 线路:默认
- 值:实例的 IP 地址
- TTL: 10 分钟
步骤#4:连接到我们的实例
您可以通过 VNC 或 SSH 连接到您的实例。VNC需要高速互联网连接,而SSH即使在慢速连接中也能正常工作。所以,我更喜欢使用SSH而不是VNC。
通过 Linux/Mac
连接 打开命令行并输入以下代码:
ssh [email protected]键入 yes 并输入 root 密码。如果密码正确,您将成功登录。
通过 Windows
连接 如果您使用的是 Windows 计算机,则需要使用第三方程序,如 PuTTY。使用 PuTTY 连接到服务器。输入实例的用户名和密码以登录
步骤#5:检查驱动程序错误
首次启动实例时,最好检查与驱动程序相关的错误消息和警告。在 Linux 中,dmesg 命令用于查看驱动程序消息。
英特尔 RAPL 驱动程序显示错误消息。如果您遇到同样的问题,可以通过运行以下命令安全地将驱动程序列入黑名单。
echo "blacklist intel_rapl" >> /etc/modprobe.d/blacklist.conf内核在下次启动时不会加载此驱动程序。通过键入重新启动命令重新启动服务器。
步骤#6:更新系统
Ubuntu 基于 Debian。APT 软件包管理器用于所有基于 Debian 的发行版,包括 Ubuntu。
apt update && apt full-upgrade -y这会将所有软件包和内核更新到最新版本。建议在分发升级后重新启动。
让我们清理系统并删除所有不再需要的包。
apt clean -y && apt remove -y步骤#7:设置默认时区
运行以下命令:
dpkg-reconfigure tzdata选择您的地理区域,然后选择您的城市。
步骤#8:安装Nginx
Nginx是一个高性能的Web服务器,能够处理数千个并发连接。它是Apache Web服务器的绝佳替代品。
在安装之前,让我们安装所需的软件包:
apt install software-properties-common zip sendmail vim nano -y您将安装最新版本的Nginx,该版本在官方Ubuntu存储库中不可用。
添加Nginx存储库:
echo "deb Index of /packages/ubuntu/ xenial nginx" >> /etc/apt/sources.list.d/nginx.list添加Nginx的签名密钥:
curl -O https://nginx.org/keys/nginx_signing.key && apt-key add ./nginx_signing.key更新软件包列表:
apt update安装NGINX:
apt install nginx -y 验证Nginx是否成功安装:
nginx -v删除默认配置:
rm /etc/nginx/sites-enabled/default rm /etc/nginx/sites-available/defaultRemove the default webpage:
rm /var/www/html/index.nginx-debian.html在启动期间启动Nginx:
systemctl enable nginx步骤#9:安装PHP-FPM
添加 PHP 7.2 PPA:
add-apt-repository ppa:ondrej/php -y更新软件包列表:
apt update安装 PHP:
apt install php7.2-fpm -y验证 PHP 是否已成功安装:
php -v安装所需的 PHP 扩展:
apt install php7.2-redis php7.2-imap php7.2-xmlrpc php7.2-mysqlnd php7.2-imagick php7.2-gd php7.2-mbstring php7.2-common php7.2-zip php7.2-curl -y在引导期间启动 PHP:
systemctl enable php7.2-fpm步骤#10:安装MariaDB
添加 MariaDB PPA:
add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirror.sax.uk.as61049.net/mariadb/repo/10.1/ubuntu xenial main' -y更新软件包列表:
apt update安装 MariaDB 服务器:
apt install mariadb-server -y在安装过程中,系统将提示您输入 root 密码。重新输入相同的密码并按Enter键。
请注意,默认安装不安全。您可以通过运行以下命令来保护安装:
mysql_secure_installation系统将要求您输入 root 密码。然后,系统将提示您一些问题。我使用了以下设置(按 Y 表示“是”,按 N 表示“否”):
- 更改根密码?不
- 删除匿名用户?是的
- 禁止远程root登录?是的
- 删除测试数据库并访问它?是的
- 是否立即重新加载权限表?是的
在启动期间启动 MariaDB:
systemctl enable mysql步骤#11:创建数据库和数据库用户
以 root 用户身份登录:
mysql -u root -p输入您的根密码。您将登录到 MariaDB 控制台。
创建新用户:
CREATE USER "example-user"@"localhost" IDENTIFIED BY "password";将“示例用户”和“密码”替换为您自己的用户名和密码。
创建新数据库:
CREATE DATABASE wordpress;向新创建的用户授予所有权限:
GRANT ALL PRIVILEGES ON . to "example-user"@"localhost";重新加载权限表:
FLUSH PRIVILEGES;退出控制台:
EXIT;步骤#12:配置Nginx
打开Nginx配置文件:
nano /etc/nginx/nginx.conf不要忘记将 example.com 替换为您的实际域名。
粘贴以下内容:
user www-data; worker_processes auto; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 10240; multi_accept on; use epoll; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; fastcgi_cache_path /var/www/cache levels=1:2 keys_zone=example.com:200m inactive=60m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; sendfile on; tcp_nopush on; tcp_nodelay on; types_hash_max_size 2048; server_tokens off; keepalive_timeout 15; client_max_body_size 512M; add_header X-Frame-Options SAMEORIGIN; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header Referrer-Policy "strict-origin-when-cross-origin"; add_header X-FastCGI-Cache $upstream_cache_status; gzip_vary on; gzip_comp_level 5; gzip_min_length 1024; gzip_proxied any; gzip_buffers 16 8k; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js; limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; limit_req_status 444; gzip on; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; server { listen 80 default_server; listen [::]:80 default_server; server_name _; return 444; } }这是我们的全球Nginx配置。要退出 nano,请按 Ctrl+O,然后点击 Enter。
您必须为您的域创建另一个:
nano /etc/nginx/sites-enabled/example.com粘贴以下内容:
server { listen 80; listen [::]:80; server_name example.com www.example.com; root /var/www/html; index index.php; set $skip_cache 0; if ($request_method = POST) { set $skip_cache 1; } if ($query_string != "") { set $skip_cache 1; } if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { set $skip_cache 1; } if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; } if ($request_uri ~* "/cart/*$|/checkout/*$|/my-account/*$") { set $skip_cache 1; } location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/run/php/php7.2-fpm.sock; fastcgi_index index.php; fastcgi_cache example.com; include fastcgi.conf; fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; fastcgi_cache_valid 10m; } location ~* \.(jpg|jpeg|gif|png)$ { expires 365d; } location ~* \.(pdf|css|ico|js|swf)$ { expires 10d; } }测试Nginx配置:
nginx -t如果测试成功,请通过键入以下内容重新启动nginx:
systemctl restart nginx步骤 13:为对象缓存配置 Redis 服务器
安装 Redis 服务器:
apt install redis-server -y在引导期间启动 Redis 服务器:
systemctl enable redis-server配置 Redis 服务器的内存限制:
echo "maxmemory 256mb" >> /etc/redis/redis.conf重新启动 Redis 服务器:
systemctl restart redis-server重新启动 PHP:
systemctl restart php7.2-fpm步骤 #14:配置 PHP
打开 PHP 7.2 配置文件:
nano /etc/php/7.2/fpm/php.ini更改以下值:
max_execution_time = 60 max_input_time = 60 memory_limit = 512M max_input_vars = 6000 upload_max_filesize = 512M post_max_size = 512M步骤#15:通过加密安装免费的SSL证书
添加让我们加密 PPA:
add-apt-repository ppa:certbot/certbot更新软件包列表 :
apt update为Nginx安装certbot:
apt-get install python-certbot-nginx -y获取 SSL:
certbot --nginx -d example.com -d www.example.com按 2 并按 Enter 键。
您将获得SSL证书,certbot将自动为您配置它。
请记住,SSL 证书将在 90 天后过期。运行以下命令以手动续订证书:
certbot renew步骤#16:安装WordPress
移动到Nginx根目录:
cd /var/www/html下载WordPress:
wget wget https://wordpress.org/latest.zip解压缩包
unzip latest.zip将所有文件移动到Nginx的根目录:
mv wordpress/* ./ && rmdir wordpress创建用于存储缓存的目录:
mkdir -p /var/www/cache更改Nginx根目录的所有权:
chown -R www-data:www-data /var/www/现在,在浏览器的地址栏中键入网站的URL。
按照屏幕上的说明完成安装。您需要输入步骤 10 中的数据库详细信息。
另外,不要忘记安装Nginx Cache和Redis Cache插件。
边栏推荐
- 2022.05.26 (lc_1143_longest common subsequence)
- 如何在VR全景作品中添加独立热点?
- 批量检测不同url的指定端口(py脚本)
- FPGA状态机
- Which school do you choose after the college entrance examination? VR panoramic campus all-round display
- FS4521恒压线性充电IC
- 2022.05.28 (lc_5_longest palindrome substring)
- Recent work
- Handwritten code bind
- Batch detection of specified ports of different URLs (py script)
猜你喜欢

First batch! Sinomenine has passed CWPP capability assessment and inspection of Xintong Institute

How to increase the monthly salary of software testing from 10K to 30K? Only automated testing can do it

LLDP协议编写要点

C (pointer 02)

Detailed interpretation of tph-yolov5 | making small targets in target detection tasks invisible

批量检测不同url的指定端口(py脚本)

测试apk-异常管控netLocation攻击者开发

FPGA状态机

高考后选择哪所学校?VR全景校园全方位展示

Flutter series: UI layout introduction
随机推荐
Performance test plan (plan) template
Flutter series: UI layout introduction
Is it safe to open an account online for futures? How to open an account specifically
融入机器学习,让Chrome浏览器更“懂”你
Development scheme of 108k humidifier for water replenishment instrument_ Single chip microcomputer_ NY8A051F_ Development of single chip microcomputer
C language floating point number storage form
On the development trend of enterprise storage: cold thoughts on open source storage
批量检测不同url的指定端口(py脚本)
Easily learn pytoch full convolution neural network to realize expression recognition
性能测试方案(计划)模板
Fs4060a is a 4.2v/3a charging IC
Mongodb 唯一索引
使用环绕通知对目标方法进行增强—摘抄笔记
企业级存储发展趋势谈:开源存储的冷思考
Zabbix_ Monitoring ssh/crond Service - wechat alarm
Zabbix_原理架构-安装部署-自定义监控
[Legendre] polynomial
Which school do you choose after the college entrance examination? VR panoramic campus all-round display
Fs4521 constant voltage linear charging IC
FS4521恒压线性充电IC