Cara Redirect Http Ke Https Nginx Permanent

Cara redirect http ke https, beberapa waktu kemudian idnetter pernah share layanan akta SSL gratis, jikalau ada yang belum baca silahkan kunjungi : SSL Gratis. Dan salah satunya dari WoSign yang menunjukkan SSL Gratis valid hingga 2 tahun, cara install sertifikatnya pun cukup gampang walau harus memahami apa itu SSL akta dan apa fungsinya paling tidak tahu sedikit saja, artikel wacana SSL sanggup anda temukan di Wikipedia.


UPDATE TERBARU : Cara redirect HTTP ke HTTPS


Setelah melaksanakan registrasi dan sedikit memodifikasi konfigurasi Nginx Server Block,  akhirnya sanggup juga merasakan HTTPS. Berikut ini panduan bagaimana cara redirect HTTP ke HTTPS di Nginx agar visitor secara permanent di redirect ke protokol HTTPS.


 


Cara Redirect HTTP ke HTTPS Nginx


Edit Nginx config pada server block, tambahkan baris berikut ini ke konfigurasi nginx, sesuaikan.


 server {
listen 80;
server_name idnetter.com www.idnetter.com;
return 301 https://$server_name$request_uri;
}

Perhatikan baris return 301… atau HTTP 301 Moved permanently, merupakan cara redirect paling efisien alasannya tidak ada regex untuk dievaluasi, pelajari lebih lanjut di pitfalls.


Dan juga tambahkan baris ini, jangan lupa sesuaikan link file akta sslnya


 server {
listen 443 ssl;
server_name idnetter.com;

# link dimana file akta berada
ssl_certificate /etc/nginx/ssl/idnetter.com_bundle.crt;
ssl_certificate_key /etc/nginx/ssl/idnetter.com.key;

...
...
}

dari konfigurasi diatas sanggup dikatakan semua pengunjung idnetter.com baik yang menggunakan WWW atau tidak akan dialihkan ke protokol https. konfigurasi nginx selengkapnya akan tampak menyerupai dibawah ini:


server {
listen 80;
server_name idnetter.com www.idnetter.com;
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
server_name idnetter.com;

client_max_body_size 5m;
client_body_timeout 60;

access_log /var/log/nginx/idnetter.com-access;
error_log /var/log/nginx/idnetter.com-error error;

root /var/www/html/idnetter/;
index index.html index.php;

ssl_certificate /etc/nginx/ssl/idnetter.com_bundle.crt;
ssl_certificate_key /etc/nginx/ssl/idnetter.com.key;

### root directory ###
location / {
try_files $uri $uri/ /index.php?$args;
}

### security ###
error_page 403 =404;
location /\. { access_log off; log_not_found off; deny all; }
location $ { access_log off; log_not_found off; deny all; }
location * wp-admin/includes { deny all; }
location * wp-includes/theme-compat/ { deny all; }
location * wp-includes/js/tinymce/langs/.*\.php { deny all; }
location /wp-includes/ { internal; }
location * wp-config.php { deny all; }
location * ^/wp-content/uploads/.*.(html|htm|shtml|php)$ {
types { }
default_type text/plain;
}

### disable logging ###
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }

### caches ###
location * \.(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; }
location * \.(woff|svg)$ { access_log off; log_not_found off; expires 30d; }
location * \.(js)$ { access_log off; log_not_found off; expires 7d; }

### php block ###
location \.php?$ {
try_files $uri =404;
include fastcgi_params;

# Sesuaikan file socket anda
fastcgi_pass unix:/var/run/gateaway.socket;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(.*)$;
#Prevent version isu leakage
fastcgi_hide_header X-Powered-By;
}

}

Save dan reload nginx


nginx -s reload

 


Setting WordPress


Jika anda menggunakan WordPress, perlu update setting pada bab General


WordPress Address (URL) : https://example.com
Site Address (URL) : https://example.com

Dengan cara tersebut semua permalink akan menggunakan awalan https. Ini merupakan solusi munculnya warning SSL pada address kafe (icon padlock dengan tanda silang merah) alasannya link gambar masih menggunakan http. Saat aku mencoba di Browser Chrome gambar juga tidak sanggup tampil, alhasil setelah diset semua memuaskan.



Sumber https://idnetter.com

Mari berteman dengan saya

Follow my Instagram _yudha58

Subscribe to receive free email updates:

Related Posts :

0 Response to "Cara Redirect Http Ke Https Nginx Permanent"

Posting Komentar