Monday, November 19, 2018

nginx - Enable Leverage Browser Caching

If you are trying to enable Leverage Browser Caching for your site in nginx and it still shows not enabled in Google PageSpeed Insights and GTmetrix.

Solution :
1) Edit file /etc/nginx/sites-enabled/default
2) Add line
expires 365d;
in your virtualhost under "server {" above "location / {"
3) Restart nginx


Example :
server {
    listen 80;
    server_name yourdomainname.com;
    expires 365d;
    client_max_body_size 128M;
    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:8080;
        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        proxy_read_timeout          600;
        send_timeout                600;
        add_header X-Frame-Options SAMEORIGIN; 
        add_header X-Content-Type-Options nosniff; 
        add_header X-XSS-Protection "1; mode=block"; 
        proxy_hide_header X-Powered-By;
        server_tokens off;
        autoindex off;
        etag off;
    }

}

Saturday, October 27, 2018

smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [Errno 104] Connection reset by peer

Django Python Error : SMTP Connection closed abruptly

If you are using Yandex smtp to send mails, here are the settings.

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.yandex.com'
EMAIL_HOST_USER = 'username@domain.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587


Do not use port 465, try with port 587.

If still it does not work, you need to check the environment variables. Have you defined DEFAULT_FROM_EMAIL or HOST in OS environment files i.e. ~/.bashrc or /etc/environment
If they are there, it may be the issue, you need to comment them and loginto the new terminal as updated settings will be affected, now restart your web server (Python) and try again sending mails.

Monday, October 15, 2018

Databases created in cpanel mysql are not visible in cpanel phpmyadmin

Solution :

  • Confirm that databases are visible under mysql section of cpanel.
  • Logout from cpanel
  • Login into cpanel again.
  • Open phpmyadmin.

Now databases should be visible in phpmyadmin