Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is an example of how to configure nginx to serve a meteor app.
server {
listen [::]:80;
listen 80;
server_name app.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen [::]:443 ssl http2;
listen 443 ssl http2;
server_name app.example.com;
ssl on;
ssl_certificate /etc/nginx/ssl/ssl.crt;
ssl_certificate_key /etc/nginx/ssl/ssl.key;
location = /favicon.ico {
root /home/ubuntu/app/bundle/programs/web.browser/app;
access_log off;
expires 1w;
}
location ~* "^/[a-z0-9]{40}\.(css|js)$" {
root /home/ubuntu/app/bundle/programs/web.browser;
access_log off;
expires max;
}
location ~ "^/packages" {
root /home/ubuntu/app/bundle/programs/web.browser;
access_log off;
}
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;
}
}
@ghost

This comment has been minimized.

Copy link

commented Sep 22, 2013

Hi, could you please put some comments to your config. Specially, the block on line
21 and 27. Because I'm a little confused how to fit it to my needs.
Thanks, dropfen

@mirageglobe

This comment has been minimized.

Copy link

commented Feb 12, 2014

Hmm. @dropfen the following may help. Its similar use but if you look at the location for css and js, it should be clear what you can modify.

http://blog.argteam.com/coding/hardening-node-js-for-production-part-2-using-nginx-to-avoid-node-js-load/

@stephentcannon

This comment has been minimized.

Copy link

commented Mar 7, 2014

i thought the recommended was was to do a return instead of a rewrite?

like

return 301 https://$server_name$request_uri?;
@stephentcannon

This comment has been minimized.

Copy link

commented Mar 8, 2014

This tid bit might be interesting to some folks that don't want the ip to be accessible and want to forward everything to their domains.

server {
  listen 80  default_server;
  server_name _;
  return 302 https://$host$request_uri;
}
@mturley

This comment has been minimized.

Copy link

commented May 20, 2014

Hi there,

I'm trying to use this configuration for my app, but I'm getting 502 Bad Gateway errors. I'm doing my app in a subdirectory, I don't know if that makes a difference. My goal is to serve the app (app name is "gnf") at https://depot.works/gnf/ (I have another static website planned for the depot.works/ root). If you're curious what my app is, I have it running and in use at gnf.meteor.com, and I'll be migrating that mongo data over too. I have it redirecting from gnf.depotstreetmarket.com to depot.works/gnf, and the redirect works, but when I land on /gnf I get a 502. And yes, my TLD is .works, it's a weird new one and I like it :)

Here's what I've got in my /etc/nginx/sites-available/gnf, I don't know if you'll see this but I'd appreciate anyone's help:

server {
  listen 80;
  server_name gnf.depotstreetmarket.com;
  rewrite ^ https://depot.works/gnf/$request_uri? permanent;
}

server {
  listen 443;
  server_name depot.works;

  ssl on;
  ssl_certificate /etc/ssl/localcerts/depot.works.crt;
  ssl_certificate_key /etc/ssl/localcerts/depot.works.key;

  location = /gnf/favicon.ico {
    root /opt/gnf/app/bundle/programs/client/app;
    access_log off;
    expires 1w;
  }

  location ~* "^/[a-z0-9]{40}\.(css|js)$" {
    root /opt/gnf/app/bundle/programs/client;
    access_log off;
    expires max;
  }

  location ~ "^/packages" {
    root /opt/gnf/app/bundle/programs/client;
    access_log off;
  }

  location /gnf {
    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;
  }
}
@radzhome

This comment has been minimized.

Copy link

commented Oct 19, 2014

I run meteor on localhost:3000 as a service, and my nginx looks like:
``
server {
listen 80;
server_name app.example.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;
}
}
``

@awrelll

This comment has been minimized.

Copy link

commented Apr 22, 2015

I tried your config @radlws but it shows me the nginx welcome page. Any suggestions ?

@sirpy

This comment has been minimized.

Copy link

commented Feb 15, 2017

you should also serve static content from public which is found under bundle/programs/app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.