网站首页 > 技术教程 正文
最近对自己的博客网站进行HTTPS化,打造一个安全的博客,博客地址:https://www.toptech.top/,,下面是具体步骤:
1、下载nginx安装包
wget -i -c http://nginx.org/download/nginx-1.17.5.tar.gz
2、安装依赖包,新版本nginx依赖zlib-devel、pcre-devel,这里我们不妨把其他的也一并安装
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
3、把下载的文件解压
tar -zxvf nginx-1.17.5.tar.gz
4、安装nginx:执行以下命令
//进入nginx
cd nginx-1.17.5
//执行命令
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
//执行make命令
make
//执行make install命令
make install
5、安装完毕之后, 我们就可以启动nginx
/usr/local/nginx/sbin/nginx
7、然后访问这个地址localhost:80,就可以看到nginx的简单界面了,nginx默认端口为:80
温馨提示:
以下是nginx常用命令,首先进入到命令目录:
cd /usr/local/nginx/sbin
然后想做什么操作,就执行什么命令吧
# 启动
./nginx
# 关闭
./nginx -s stop
# 重启
./nginx -s reload
8、HTTPS具体配置
首先需要申请SSL安全证书,这里使用的阿里云DigiCert证书签发服务,DigiCert在2017年12月1日并购了Symantec,大家不用担心证书安全问题,这里选择免费型DV SSL为例子演示,然后根据阿里云提示操作一步步申请即可:搜索SSL证书
这里我们选择右边的免费版
点击证书申请
申请审核的时间很快的,两分钟成功后如下
下载证书,这里使用的是nginx ,所以
9、证书申请下来以后,下载nginx版本的证书,解压文件以后,里面有两个文件:
www.toptech.top.pem #证书文件
www.toptech.top.key #证书的密钥文件
10、把这两个文件上传到nginx服务器,例如:我把文件放在了/usr/local/nginx/cert下
11、现在配置nginx的https,编辑nginx.conf文件:
vim /usr/local/nginx/conf/nginx.conf
内容如下
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
# 服务器主机配置:server ip:port weight=权重;
upstream toptech{
server 120.76.62.79:8080 weight=1;
server 120.76.62.79:8080 weight=1;
server 120.76.62.79:8080 weight=1;
server 120.76.62.79:8080 weight=1;
server 120.76.62.79:8080 weight=1;
server 120.76.62.79:8080 weight=1;
server 120.76.62.79:8080 weight=1;
server 120.76.62.79:8080 weight=1;
}
# 设置nginx允许上传文件的大小
client_max_body_size 10m;
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
# 开启gzip压缩
gzip on;
server {
# 监听80端口
listen 80;
# 配置服务名称
server_name www.toptech.top;
# 监听到http的80端口请求,进行https跳转
return 301 https://$server_name$request_uri;
#charset koi8-r;
#access_log logs/host.access.log main;
# location / {
# proxy_pass http://toptech;
# }
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
# 这里就是HTTPS的配置了
server {
# 监听443端口
listen 443 ssl;
# 服务名称
server_name www.toptech.top;
# 这里配置SSL证书
ssl_certificate /usr/local/nginx/cert/www.toptech.top.pem;
# 这里配置SSL证书的密钥
ssl_certificate_key /usr/local/nginx/cert/www.toptech.top.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
# 这里是监听到443端口的请求的跳转链接
proxy_pass http://toptech.top:8080;
}
}
}
12、配置完毕重启nginx
./nginx -s reload
以上端口为8080,是因为我的项目运行端口为8080,这个看情况而定,如果网站显示还是不安全,说明网页内存在不是https的图片
猜你喜欢
- 2024-10-11 文件上传漏洞是什么?这么通俗易懂的讲解真的很难得!
- 2024-10-11 记录一次Ng+.NetCore大文件上传的错误排查
- 2024-10-11 php nginx 修改文件上传最大大小(nginx 文件大小限制)
- 2024-10-11 利用Nginx实现免上传安装zabbix agent
- 2024-10-11 Nginx入门到实战-常见问题(nginx操作)
- 2024-09-21 H5+JAVA的文件上传,断点续传(h5加java)
- 2024-09-21 运维必备核心技能-nginx实现web服务配置
- 2024-09-21 如何用 Python 快速实现 HTTP 和 FTP 服务器
- 2024-09-21 实战Django:轻松解决上传图片无法显示的问题
- 2024-09-21 如何实现大文件上传、断点续传、切片上传
你 发表评论:
欢迎- 最近发表
-
- Linux新手必看:几种方法帮你查看CPU核心数量
- linux基础命令之lscpu命令(linux中ls命令的用法)
- Linux lscpu 命令使用详解(linux常用ls命令)
- 如何查询 Linux 中 CPU 的数量?这几个命令要知道!
- 在linux上怎么查看cpu信息(linux如何查看cpu信息)
- 查看 CPU 的命令和磁盘 IO 的命令
- 如何在CentOS7上改变网卡名(centos怎么改网卡名字)
- 网工必备Linux网络管理命令(网工必备linux网络管理命令是什么)
- Linux 网络命令知多少(linux 网络 命令)
- Linux通过命令行连接wifi的方式(linux命令行连接无线网)
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)