Created
August 11, 2018 22:45
-
-
Save lukaszflorczak/2d79887c5825e99e94b26f09b9c44830 to your computer and use it in GitHub Desktop.
Nginx configuration for Nuxt.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
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;
}
}
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?
You may want to check this config too:
@lukaszflorczak it works fine for me thank you it can change localhost:3000 to my IP with my ufw port is works too.
Actually the original answer is flawed, it performs suboptimal. No need to have those upgrade headers in place.
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
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.