Nginx And Apache2 Redirect and HTTPS (SSL Certificate Template)


NGINX


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

Apache


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


NameVirtualHost *:80
<VirtualHost *:80>
   ServerName www.yourdomain.com
   Redirect / https://www.yourdomain.com
</VirtualHost>

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


</VirtualHost>

change / merge this config into your site config file.

restart apache

service apache2 restart

28747008

Leave a Reply

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