Search code examples
node.js.htaccessnginxdigital-oceanghost

Add htaccess to a Ghost project


I´m trying to add a .htaccess to my ghost project to enable the gzip compression, Im serving my project in Nginx Ubuntu 16 and Ghost-cli, i see that sites-avalable generates a proxy that redirects to the node that runs on localhost:2368, this is the configutation

server {

server_name latribu.mx www.latribu.mx;
root /var/www/latribu.mx/html/system/nginx-root;

location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    proxy_pass http://127.0.0.1:2368;

}

location ~ /.well-known {
    allow all;
}

client_max_body_size 50m;

listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/latribu.mx/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/latribu.mx/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
if ($host = latribu.mx) {
    return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = www.latribu.mx) {
    return 301 https://$host$request_uri;
} # managed by Certbot

listen 80;
listen [::]:80;

server_name latribu.mx www.latribu.mx;
return 404; # managed by Certbot
}

How can i add .htaccess file to my project


Solution

  • Nginx does not support .htaccess file like Apache. If you want to enable GZip with Nginx, open /etc/nginx/nginx.conf. Scroll down to the GZip settings section and add these lines.

    gzip on;
    
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    

    Then restart Nginx with service nginx restart.