Linux Nginx Web环境安装SSL证书后强行指向HTTPS方法
如今我们越来越多的网站需要使用SSL证书,尤其是一些购物类网站,用户交互类网站使用居多。安装方法也很简单,我们可以根据自己的服务器是NGINX还是APACHE进行安装,但是在安装之后,默认的HTTP和HTTPS都会指向的网站。这里需要考虑到唯一性和权重的转移,我们需要将HTTP强制转向HTTPS,这里示范下看看NGINX WEB环境是如何设置的。
server { listen 80; server_name cnbanwagong.com www.cnbanwagong.com; rewrite ^/(.*) https://www.cnbanwagong.com/$1 permanent; } server { listen 443; server_name cnbanwagong.com www.cnbanwagong.com; root /home/www/cnbanwagong.com/; index index.php index.htm index.html; # charset gb2312; charset utf-8; access_log logs/test_access.log main; #access_log off; #error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ .+.(php|do)?$ { fastcgi_pass unix:/var/run/phpfpm.socket; # fastcgi_pass unix:/usr/local/webserver/fastcgi/sock/fastcgi.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } ssl on; ssl_certificate /data/nginx/conf/hd86_org_key/hd86_org.crt; ssl_certificate_key /data/nginx/conf/hd86_org_key/server.key; # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ .+.(dat|sql|tgz|gz|tar|zip)?$ { deny all; } location ~ /.ht { deny all; } }
修改我们当前站点的NGINX配置,添加443端口,我们只需要将特定的域名换成我们自己的就可以。
最后,重启NGINX就可以生效。