目录
配置ssl证书之前,先准备ssl证书,至于获取的途径很多(阿里云服务,第三方购买)

我这里购买的是阿里云的免费证书。

买完申请一下就行。

下载nginx专用的就行
如果我们已经安装了nginx我们就需要对他进行重新的编译安装。
编译前需要安装的依赖环境
yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel make
开始编译
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module

make &&make install
nginx -V #验证一下模块是否添加

- #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 {
- 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 on;
- server {
- listen 443 ssl;
- server_name www.yz1999.top; #证书绑定域名
-
- ssl_certificate /usr/local/8399859_www.yz1999.top.pem; #添加.pem路径
- ssl_certificate_key /usr/local/8399859_www.yz1999.top.key; #添加.key路径
-
- ssl_session_cache shared:SSL:1m;
- ssl_session_timeout 5m;
-
- ssl_ciphers HIGH:!aNULL:!MD5; #表示使用的加密套件的类型
- ssl_prefer_server_ciphers on;
-
- location / {
- root html;
- index index.html index.htm;
- }
- }
-
- server {
- listen 80;
- server_name localhost;
- rewrite ^/(.*) https://www.yz1999.top/$1 redirect; #将所有HTTP请求通过rewrite指令重定向到HTTPS。
- #charset koi8-r;
-
- #access_log logs/host.access.log main;
-
- #location / {
- # root html;
- # index index.html index.htm;
- #}
-
- #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;
-
- # 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;
- #
- #server {
- # listen 8000;
- # listen somename:8080;
- # server_name somename alias another.alias;
-
- # location / {
- # root html;
- # index index.html index.htm;
- # }
- #}
-
-
- # HTTPS server
- #将ssl证书绑定到www.yz1999.top上
- }
-
重新加载一下配置文件
我们去访问一下,这里输入IP也能自动跳转到域名访问

发现红框内变成安全图标,到此就完成配置了。