WebFaction
Community site: login faq

I've just been through the docs looking at setting up multiple applications on the same domain but different paths, ie. www.mysite.org = static application, www.mysite.org/forum = Django app.

I have set up two sample applications within a single domain to see how it works but I could do with understanding how this is achieved technically underneath on the Apache webserver. I'm wanting to set up a simulation of this method for development purposes on my test server.

I'm not sure if I should be looking at virtualhosts or something different, any help appreciated.

asked 14 Aug '15, 18:03

zilog8bit
(suspended)
accept rate: 0%


If you're using Apache as the front-end on your test server, then you should use a VirtualHost for the overall site, and Location blocks for each URL path.

We're using Nginx on the front-end here - the generated web server configuration for what you've described looks like this:

server {
    listen       37.58.75.248:80;
    listen       [2a03:8180:1001:b2:43::14]:80;
    server_tokens off;
    server_name_in_redirect off;

    more_clear_input_headers Forwarded_Request_URI;
    more_clear_input_headers X_Forwarded_Host;
    more_clear_input_headers X_Forwarded_Server;
    more_clear_input_headers X_Forwarded_For;
    more_clear_input_headers X_Forwarded_Proto;
    more_clear_input_headers X_Forwarded_SSL;

    proxy_set_header  Host                      $host;
    proxy_set_header  X-Forwarded-Host          $host;
    proxy_set_header  X-Forwarded-Server        $host;
    proxy_set_header  X-Forwarded-For           $proxy_add_x_forwarded_for;
    proxy_set_header  Forwarded-Request-Uri     $request_uri;

    proxy_set_header  Http-X-Forwarded-Proto  http;
    proxy_set_header  Https                   off;
    proxy_set_header  X-Forwarded-Proto       http;
    proxy_set_header  X-Forwarded-SSL         off;

  server_name  username.webfactional.com;

    location /forum/ {
        rewrite  ^(/forum)$ $1/;
        rewrite  ^/forum(.+) $1  break;

        proxy_pass  http://localhost:54321;
    }

    location = /forum {
        rewrite  ^(/forum)$ $1/;
        rewrite  ^/forum(.+) $1  break;

        proxy_pass  http://localhost:54321;
    }

    location / {
        alias  /home/username/webapps/static_app/;
        index  index.html index.htm index.txt;
        expires max;

        if ($request_filename !~ /home/username/(.*)) {
            return 403;
        }
    }

    location = / {
        alias  /home/username/webapps/static_app/;
        index  index.html index.htm index.txt;
        expires max;

        if ($request_filename !~ /home/username/(.*)) {
            return 403;
        }
    }


    access_log  /home/username/logs/frontend/access_username.log combined;
    error_log   /home/username/logs/frontend/error_username.log notice;
    }

The "server" block is the equivalent of an Apache VirtualHost, and the "location" blocks are the same as an Apache Location block. The static app is a straight directory mapping, while the Django app is served via proxy_pass going to the app's port (54321 in this example).

Hope that helps!

permanent link

answered 14 Aug '15, 18:40

seanf
12.2k42136
accept rate: 37%

Thanks Sean, exactly what I was looking for. Might try my first Nginx setup too, very clear example to follow in your post.

(14 Aug '15, 19:57) zilog8bit
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×225
×17
×11
×8

question asked: 14 Aug '15, 18:03

question was seen: 3,248 times

last updated: 14 Aug '15, 20:05

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM