Welcome! Log In Create A New Profile

Advanced

Subdomain with static files besides a Rails app

Posted by Jason17 
Subdomain with static files besides a Rails app
April 07, 2013 01:37PM
I have a Rails based API that runs on a backend Nginx server and is stable. The server is not reachable from the outside, it has an Apache as a proxy before it. The API is available via a subdomain: api.myapp.net.

Now I'd like to server a static single page application via a second subdomain: alpha.myapp.net. The subdomain is configured, has a correct A-Record. Apache proxies traffic for api. and alpha. to the correct backend server using this simple config:

<VirtualHost *:80>
ServerAdmin webmaster@myapp.net
ServerName myapp.net
ServerAlias myapp.net *.myapp.net

DirectoryIndex index.html

RewriteEngine On

RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 9

RewriteCond %{HTTP_HOST} !^(alpha\.|api\.)?myapp\.net$
RewriteRule ^(.*)$ http://myapp.net$1 [L,R=301]

ProxyPass / http://192.168.1.145/
ProxyPassReverse / http://192.168.1.145/

ErrorLog /var/log/apache2/error.log

LogLevel warn

CustomLog /var/log/apache2/access.log combined
ServerSignature Off
</VirtualHost>

The Nginx is configured as follows:

worker_processes 8;

events {
worker_connections 1024;
}

http {
passenger_root /usr/local/rvm/gems/ruby-1.9.2-p320/gems/passenger-3.0.17;
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p320/ruby;

include mime.types;
default_type application/octet-stream;

sendfile on;
tcp_nopush on;
tcp_nodelay off;

gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types application/json text/plain text/xml text/css
text/comma-separated-values
text/javascript application/x-javascript
application/atom+xml;

upstream myapp {
server localhost:80;

server {
listen 80;
server_name api.myapp.net;
passenger_enabled on;
root /home/deployer/apps/myapp/current/public;
}

server {
listen 80;
server_name alpha.myapp.net;
passenger_enabled off;
root /home/deployer/apps/client/current;
}
}

What happens now is, that all traffic to alpha.myapp.net hits the Rails application that serves the api. My static site under /home/deployer/apps/client/current is never served.

What am I doing wrong / missing?

Regards Felix
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 85
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready