密钥文件
将从腾讯云下载的密钥文件放到服务器上,可放到如下目录
/etc/ssl/certs/
nginx配置文件如下
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server{
listen 80;
server_name xjtumbatest.cn;
rewrite ^/(.*)$ https://xjtumbatest.cn:443/$1 permanent;
}
server{
#监听443端口
listen 443;
server_name xjtumbatest.cn;
ssl on;
#从腾讯云获取到的第一个文件的全路径
ssl_certificate /etc/ssl/certs/xjtumbatest.cn/1_xjtumbatest.cn_bundle.crt;
#从腾讯云获取到的第二个文件的全路径
ssl_certificate_key /etc/ssl/certs/xjtumbatest.cn/2_xjtumbatest.cn.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
root /usr/share/nginx/html/stu_manage/public;
index index.php index.html;
#这是我的主页访问地址,因为使用的是静态的html网页,所以直接使用location就可以完成了。
location / {
index index.php index.html error/index.html;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
autoindex off;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
共两个server
第一个是将80端口重定向到https,也就是443端口,http状态码是301,对用户是无感知的
第二个是https的,密钥文件路径不能填错