前情提要,花了1美元买了一年的LXC架构小鸡,测试完之后开始折腾,准备安装nginx做IPv6站点。涉及到Nginx和Let's Encrypt TLS/SSL配置。

Nginx安装与配置

更新并安装Nginx

apk update
apk add nginx

为Nginx增加www用户并新增对应文件夹

adduser -D -g 'www' www
mkdir /www
chown -R www:www /var/lib/nginx
chown -R www:www /www

创建Nginx配置文件

mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig
vim /etc/nginx/nginx.conf #这里使用vim新建/编辑

以下为nginx.conf的内容,要注意listen [::]:80;才能使用IPv6访问,负责只能使用IPv4连接。

user www;
worker_processes auto; # it will be determinate automatically by the number of core
error_log /var/log/nginx/error.log warn;
#pid /var/run/nginx/nginx.pid; # it permit you to use /etc/init.d/nginx reload|restart|stop|start
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
access_log /var/log/nginx/access.log;
keepalive_timeout 3000;
server {
listen [::]:80;
root /www;
index index.html index.htm;
server_name localhost;
client_max_body_size 32m;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/lib/nginx/html;
}
}
}

新建一个测试页面,vim /www/index.html,内容如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>HTML5</title>
</head>
<body>
Server is online
</body>
</html>

支持,Nginx已经安装并配置完成,需要测试配置文件和启动。

rc-update add nginx default # 设置开机自启
rc-service nginx reload # 重新加载配置文件
rc-service nginx restart # 重启Nginx

此外还可以用nginx -t查看配置文件是否出错,以下是支持的反馈:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Let's Encrypt TLS/SSL安装与配置

用acme.sh吧,垃圾KXC 64MB小鸡,什么都干不了,不搞了。

标签: vps, lxc

添加新评论