Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Subdomain with static files besides a Rails app

$
0
0
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

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>