Proxy Server

Overview

DreamHost offers a Proxy Server you can use to configure an application to run on a non-privileged port without binding the port # to the URL. This service is available on VPS or Dedicated Server hosting plans running either Nginx or Apache.

This article explains how DreamHost's Proxy Server is configured and examples of how to create a stand-alone server for Node.js and Python apps.

Technical details

DreamHost's Proxy Server is a reverse proxy using Apache mod_proxy

Ports

You can only forward requests to daemons bound to all hosts using ports between 8000-65535.

Ports 80 and 443 cannot be used, however, the Proxy Server will use your SSL certificate to encrypt all connections.

DreamHost does not employ any sort of firewall or port blocking on its network.

Daemon

A daemon process is a server process that listens for communication from remote clients. Daemon processes that bind to a port (on which they listen for incoming connections) are visible from the Internet.

DreamHost VPS and Dedicated servers permit you to run daemon server processes, but please note they are limited to the server resources (CPU/RAM) of your plan type.

Configure a Proxy Server

To configure a Proxy Server:

  1. Navigate to the Proxy page.
    proxy domain
  2. Enter the following:
    • URL to set up Proxy under: Choose your domain from the dropdown.

      url/to/proxy/

      • Primary directory: To use the primary web directory, you must clear this field.
      • Subdirectory: To use a subdirectory, type in its name.
    • Port Number to Proxy: Enter the port # you configured your app to use.
  3. Click the Add Proxy Server... button.

Stand-alone server examples

The following Node.js and Python examples show how to create a simple server to run on port #8002 for you to proxy.

Node.js

  1. Install a custom version of Node.js.
  2. In the app directory (example.com), create a file named app.js with the following code:
    var http = require("http");
    
    var server = http.createServer(function (request, response) {
      response.writeHead(200, {"Content-Type": "text/plain"});
      response.end("Hello World From Node");
    }).listen(8002);

    The listen function tells node which port the application to listen on.

  3. Start the default node server by running the app.js file.
    [server]$ node app.js

    This loads the app.js file only while your current SSH session is still active. You can also use a package such as Forever which would allow you to exit the SSH session while continuing to run the app.

  4. Visit the domain (without the port added to the URL) and you will see the application run.

Python

A common standalone server used for Python applications is Gunicorn inspired by the Ruby Unicorn server.

You must first install a custom version of Python. This allows you to create a virtualenv and install custom Python modules locally.

  1. Make sure you have activated your virtualenv. The first part of your command prompt changes to the name of your virtualenv.
  2. After you activate your virtualenv, use pip to install Gunicorn:
    (venv)[server]$ pip3 install gunicorn
  3. Create a Python file to run the site. This example is named myapp.py:
    (venv)[server]$ vim myapp.py
  4. Add the following code to the file:
    def app(environ, start_response):
      data = b"Hello, World From Gunicorn!"
      start_response("200 OK", [
          ("Content-Type", "text/plain"),
          ("Content-Length", str(len(data)))
                               ])
      return iter([data])
  5. Start Gunicorn by passing in the port # to the command.
    Make sure to change example.com to your domain name.

    Adding --log-level=debug provides helpful information if an error occurs. You can then share this information when contacting support to help identify the issue.

    (venv)[server]$ GUNICORN_CMD_ARGS="--bind=example.com:8002" gunicorn myapp:app --log-level=debug
  6. Visit the domain and you will see  'Hello, World From Gunicorn!'.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?