Best Way to redirect HTTP to HTTPS in NGINX Server Configuration

Edit your vhost config domain in Nginx direfctory ex: /etc/nginx/site-available/

server {
listen *:80;
return 301$request_uri;
server {
listen *:443 ssl;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /var/www/web4/ssl/;
ssl_certificate_key /var/www/web4/ssl/;
root /var/www/;
try_files $uri $uri/ /index.php;
index index.php;
error_log /var/log/httpd/;
access_log /var/log/httpd/ combined;
location = /favicon.ico {
log_not_found off;
access_log off;
location @php {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php7-fpm/web.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your e-mail address will not be published. Required fields are marked *