### 1.下载证书
选nginx,证书和秘钥文件。
2.放置服务器上
创建文件夹,可放在nginx的目录下。上传文件。
mkdir cert
root@hecs-139923:/etc/nginx/cert# ll
total 16
drwxr-xr-x 2 root root 4096 Feb 2 09:15 ./
drwxr-xr-x 9 root root 4096 Feb 2 11:52 ../
-rw-r--r-- 1 root root 1675 Feb 2 09:15 jingxiuwb.top.key
-rw-r--r-- 1 root root 3830 Feb 2 09:15 jingxiuwb.top.pem
3.改写配置nginx.conf
要点:
1、在https中加入server相关配置。
证书目录、root目录、index、调整php的location。
2、屏蔽之前的include ,其中包含了原调整路径。
完整配置文件参考:/etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
server {
listen 443 ssl;
server_name jingxiuwb.top;
ssl_certificate /etc/nginx/cert/jingxiuwb.top.pem;
ssl_certificate_key /etc/nginx/cert/jingxiuwb.top.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
root /var/www/html/wordpress;
index index.html index.htm index.nginx-debian.html index.php;
server_name _;
location / {
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
}
4.重载命令
#检查语法
nginx -t
#
nginx -s reload
#或重新服务
systemctl restart nginx
#检查进程
ps -ef | grep nginx
其他:
若浏览器访问不到,可清除浏览器缓存数据。
标签:ssl,证书,etc,server,nginx,include,root From: https://www.cnblogs.com/xjxlb/p/18002948