Nginx And Apache2 Redirect and HTTPS (SSL Certificate Template)


edit your site config file, default location /etc/nginx/sites-enable/default

server {
    listen 80 default_server;
    server_name _;
    return 301 https://$host$request_uri;


server {
        listen 443 ssl;

        ssl_certificate path/fullchain.pem;
        ssl_certificate_key path/privkey.pem;


replace http config, and merge https config into existing config for site. change path to the ssl_certificate/ssl_certificate_key

restart nginx

service nginx restart


edit your site config file, default located under /etc/apache2/sites-enabled/

NameVirtualHost *:80
<VirtualHost *:80>
   Redirect /

<VirtualHost _default_:443>
   DocumentRoot /usr/local/apache2/htdocs
   SSLEngine On
   SSLCertificateFile path/fullchain.pem;
   SSLCertificateKeyFile path/privkey.pem;


change / merge this config into your site config file.

restart apache

service apache2 restart


Leave a Reply

Your email address will not be published. Required fields are marked *