Skip to content

Instantly share code, notes, and snippets.

@lukaszflorczak
Created August 11, 2018 22:45
Show Gist options
  • Save lukaszflorczak/2d79887c5825e99e94b26f09b9c44830 to your computer and use it in GitHub Desktop.
Save lukaszflorczak/2d79887c5825e99e94b26f09b9c44830 to your computer and use it in GitHub Desktop.
Nginx configuration for Nuxt.js
server {
listen 80;
listen [::]:80;
index index.html;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
@imsidz
Copy link

imsidz commented Apr 8, 2019

this is working fine
but
how to host nuxt in ssl
its not working

@damqhieu
Copy link

i have same problem. You had solutions

this is working fine
but
how to host nuxt in ssl
its not working

@forrust
Copy link

forrust commented Mar 9, 2020

someone found a solution to work nginx reverse proxy with ssl?

@azrikahar
Copy link

someone found a solution to work nginx reverse proxy with ssl?

If you are not opposed to going the docker route, this nginx-proxy container has a companion container for SSL support using Let's Encrypt which is fairly straightforward to setup.

@pmanikas
Copy link

pmanikas commented Feb 8, 2021

This is my nuxt-nginx setup located on /etc/nginx/sites-available/domain-name.conf and it works with ssl flawlessly. Of course you'll have to generate your certification keys for your domains.

server {                                                                                                         
        listen 80;
        listen 443 ssl;
        server_name domainname.com;

        gzip on;
        gzip_types	text/plain application/xml;
        gzip_proxied    no-cache no-store private expired auth;
        gzip_min_length 1000;

        ssl_certificate     /etc/nginx/ssl/cert.crt;
        ssl_certificate_key /etc/nginx/ssl/cert.key;

        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!MD5;

        # This is a cache for SSL connections
        ssl_session_cache shared:le_nginx_SSL:1m;
        ssl_session_timeout 1440m;

        rewrite ^/(.*)/$ /$1 permanent;


        location / {
                proxy_set_header        Host $host;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        X-Forwarded-Proto $scheme;
                proxy_redirect          off;
                proxy_buffering         on;
                proxy_cache             STATIC;
                proxy_cache_valid	200 1d;
                proxy_cache_use_stale   error timeout invalid_header updating http_500 http_502 http_503 http_504;

                proxy_pass              http://localhost:3006;
                proxy_read_timeout	1m;
                proxy_connect_timeout   1m;
        }
}

@khrelian
Copy link

I'm fairly new to deploying into a ubuntu server. I have the same config as the above, but my images and some of my js files keep getting 404 errors. What am I doing wrong?

@VivianSolide
Copy link

You may want to check this config too:

https://nuxtjs.org/docs/2.x/deployment/nginx-proxy

@khosokha
Copy link

khosokha commented Sep 8, 2021

@lukaszflorczak it works fine for me thank you it can change localhost:3000 to my IP with my ufw port is works too.

@jonathanniels
Copy link

Actually the original answer is flawed, it performs suboptimal. No need to have those upgrade headers in place.

@kelvz-hub
Copy link

kelvz-hub commented Dec 13, 2022

Hi, can someone give a step by step on how to setup a like htaccess nginx on my nuxtjs project in localhost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment