Best Way to redirect HTTP to HTTPS in NGINX Server Configuration

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

server {
listen *:80;
server_name your-domain.com www.your-domain.com;
return 301 https://your-domain.com$request_uri;
}
server {
listen *:443 ssl;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /var/www/web4/ssl/your-domain.com-le.crt;
ssl_certificate_key /var/www/web4/ssl/your-domain.com-le.key;
server_name your-domain.com www.your-domain.com;
root /var/www/your-domain.com/web/;
try_files $uri $uri/ /index.php;
index index.php;
error_log /var/log/httpd/your-domain.com/error.log;
access_log /var/log/httpd/your-domain.com/access.log 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 *

*