搭建步驟
- 安裝 nginx
- 生成證書
- 修改 config
- 重啟 nginx
安裝 nginx
apt 安裝:
sudo apt-get install nginx
生成證書
使用 openssl 生成證書:
到對應(yīng)的路徑下:/etc/nginx/ssl/
openssl genrsa -des3 -out shidian.key 1024
openssl req -new -key shidian.key -out shidian.csr
cp shidian.key shidian.key.org
openssl rsa -in shidian.key.org -out shidian.key
openssl x509 -req -days 365 -in shidian.csr -signkey shidian.key -out shidian.crt
修改 config
修改 nginx 對應(yīng)的 config 文件:/etc/nginx/site-enable/default
文章來源:http://www.zghlxwxcb.cn/news/detail-738312.html
# SSL配置
server {
listen 443 ssl; #SSL協(xié)議訪問端口號為443。此處如未添加ssl,可能會造成Nginx無法啟動。
server_name localhost; #(改)將localhost修改為您證書綁定的域名,例如:www.example.com。
#index index.htm index.html; #默認(rèn)文件
#root /usr/share/nginx/html/;
ssl_certificate /etc/nginx/ssl/shidian.crt;
ssl_certificate_key /etc/nginx/ssl/shidian.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用該協(xié)議進(jìn)行配置。
ssl_prefer_server_ciphers on;
#wordpress偽靜態(tài),不是wordpress應(yīng)該就不用加了
location / {
root /usr/share/nginx/html;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
charset utf-8;
}
#這段是必備,沒有好像就不能正常運行,加了就是了
location ~* \.(eot|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin '*';
}
}
重啟 nginx
sudo nginx -t #測試配置是否正確
sudo nginx -s reload
文章來源地址http://www.zghlxwxcb.cn/news/detail-738312.html
到了這里,關(guān)于Ubuntu 使用 nginx 搭建 https 文件服務(wù)器的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!