nginx配置ssl证书
1. 申请一个ssl证书,把文件下载下来
2. mac电脑用scp命令将文件上传到linux服务器上
文件上传
scp local_file remote_username@remote_ip:remote_folder
文件夹上传(-r
)
scp -r local_file remote_username@remote_ip:remote_folder
3. nginx配置(mac可用curl ipinfo.io/json
命令行查看本机公网ip)
server {
listen 443 ssl;
server_name 域名;
ssl_certificate .crt文件位置;
ssl_certificate_key .key文件位置;
access_log /var/log/nginx/自定义名称.access.log main; //访问日志
error_log /var/log/nginx/自定义名称.error.log; //错误日志
location / {
root 根目录; // 服务器文件的根目录
index index.html index.htm;
try_files $uri $uri/ /index.html?$query_string;
allow 具体ip/ip段; //仅允许特定的ip/ip段访问
deny all;
}
}
server {
listen 80;
server_name 域名;
return 301 https://域名$request_uri;
}