其他配置
(1)301跳转:下面的配置文件中,将www跳转到@,http强制跳转到https。
(2)调整文件上传大小:调整文件上传大小为100M(如不调整,默认2M)。
最终得到的总体nginx配置文件如下:
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server {
listen 80;
server_name domainexample.com;
return 301 https://$server_name$request_uri;
}
server {
listen *:80;
listen *:443 ssl;
listen [::]:80;
listen [::]:443 ssl;
server_name www.domainexample.com;
ssl_certificate /etc/nginx/ssl/domainexample.com/fullchain;
ssl_certificate_key /etc/nginx/ssl/domainexample.com/key;
return 301 https://domainexample.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domainexample.com;
access_log /var/log/nginx/host.access.log main;
client_max_body_size 100M;
# certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
ssl_certificate /etc/nginx/ssl/domainexample.com/fullchain;
ssl_certificate_key /etc/nginx/ssl/domainexample.com/key;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
# intermediate configuration. tweak to your needs.
ssl_protocols TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
# HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
add_header Strict-Transport-Security max-age=15768000;
# OCSP Stapling ---
# fetch OCSP records from URL in ssl_certificate and cache them
ssl_stapling on;
ssl_stapling_verify on;
## verify chain of trust of OCSP response using Root CA and Intermediate certs
ssl_trusted_certificate /etc/nginx/ssl/domainexample.com/fullchain;
resolver 8.8.8.8;
root /home/username/domainexample.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ = 404;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
location /.well-known/acme-challenge/ {
alias /home/username/domainexample.com/.well-known/acme-challenge/;
}
location ~ \.pl|cgi$ {
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_index index.pl;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
(3)安装imagemagick模块,保证MT后台不报错:
apt install imagemagick libimage-magick-perl
(4)安装sendmail:
apt install sendmail
配置可在Webmin中操作。
(5)调整perl编码识别,以防出现错误:
在Webmin面板,以root登录,在File Manager中,修改/usr/lib/x86_64-linux-gnu/perl/5.24/Encode.pm,在第201行else {
后面,添加
Encode::_utf8_off($octets);
点击最下方Save and close(保存并关闭)即可。
好了,配置完成。
接下来,上传文件、设置数据库,以至于后期的备份数据库、修改文件等,均可在Webmin面板操作。
清除缓存软件包
从Debian和Ubuntu的软件仓库下载的软件包并不会默认删除。为释放被占用的空间,可执行
apt clean
即可删除软件仓库下载的软件包。
安装Movable Type
安装步骤可参见官方文档,但官方文档说的太复杂了。此处则简略的一下。
将mt-static目录独立出来,剩余的文件放在同一个目录,命名为cgi-bin。将cgi-bin和mt-static上传到网站根目录。
访问domainexample.com/cgi-bin/mt/mt.cgi,进入安装过程。
安装过程中,有一步是发送邮件设置。如果使用sendmail,需要输入路径。本文前面安装的sendmail所在路径为:
/usr/lib/sendmail
最后写入数据库这一步需要注意,如果在浏览器端,可能长时间没有反应。解决方法:使用手机浏览器访问,即可正常进行最后写入数据库这一步。这可能是bug。
部分文件夹需要将权限设置为777,待安装结束后,进入后台,按警告内容提示操作。
示例站点:https://iyfy.top 。注:如果示例站点不能访问,可能的原因有:
- VPS宕机、过期或被删除
- 后期折腾时操作出现错误,或网站运行中出现我无法解决的错误
- 我主动关停了这个站点
- 我被迫关停了这个站点
- 网络原因或境内电信运营商原因
- ip、域名或DNS服务器被X
- 域名被注册局(-江苏邦宁科技有限公司)或注册商(阿里云)停止解析
- 域名过期
最后,感谢某大佬提供了为期一年的VPS供我折腾。
善意的提醒一下:VPS属于无服务模式,除非付费寻求技术服务,一切使用和维护工作均只能由用户独立完成。当出现故障时,需用户自行保证数据安全。如果没有足够的VPS管理经验,却也想自己折腾一下,请不要将重要数据放到VPS上。
19 条回复
好详细的文章! 赞
谢谢大佬的鼓励!
看来还是用宝塔比较好啊,哈哈
宝塔是方便,然而呢,我折腾的时候总是有环境安装失败,比如php 7.0~7.2,mysql 5.1。又没有我看得懂的警告信息。不知道怎么回事。