Redirecting subdomain to port 3000

With wordpress frontpage running at port 80 (mysaas.com) I would like subdomain app.mysaas.com to point to port running meteor 3000. Is there easy way to do it?

Are you using apache or nginx?

Apache, I have seen the Apache reverse proxy advice elsewhere but I guess this would be extra layer. I mean, if reverse proxy is the only way, then it should be somehow done through its internal node but not extra Web-server.

I’ve switched primarily to nginx, but in looking over some old apache server configs, I’ve also used mod_proxy, so I think you are probably on the right path. Without getting into load balancing, etc., I think the reverse proxy will be your most straightforward approach.

I see. Would be grateful for meteor-specific nginx configs, if this is more straightforward path I would rather rely on nginx for app architecture.

I use mup to deploy (in this case to port 3005) and then use the following config:

server {
        listen   80;
        server_name subdomain.domain.com;

        root /dev/null;
        location / {
                proxy_pass http://localhost:3005;
                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;
        }
}

For something like wordpress, I use:

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  gzip on;
  gzip_min_length  1100;
  gzip_buffers  4 32k;
  gzip_types    text/plain application/x-javascript text/xml text/css;
  gzip_vary on;

  root /var/www/domain.com/html;

  index index.html index.htm index.nginx-debian.html index.php;

  server_name domain.com www.domain.com;

  location / {
    try_files $uri $uri/ =404;
  }

  location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
    expires 365d;
  }

  location ~ \.php$ {
   try_files $uri =404;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_pass unix:/var/run/php5-fpm.sock;
   fastcgi_index index.php;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include fastcgi_params;
  }

}

Note that if you’re on Ubuntu, running nginx, and you want to run Wordpress, you will need to use php5-fpm, which makes the fastcgi_pass variable different. There is a good write up on digitalocean about getting this setup going, and the server block code above is based on that article.

If it seems like too much work to swap to nginx, maybe just stick with the reverse proxy on apache?

2 Likes

Throwing in a quick Apache config example for completeness:

<VirtualHost *:80> 
  ServerName app.mysaas.com
  ProxyPreserveHost On
  ProxyPass / http://127.0.0.1:3000/
  ProxyPassReverse / http://127.0.0.1:3000/
</VirtualHost>
1 Like

Many thanks. Yes, I think it would be wise to start with Apache and then move to nginx config in case of necessity.