Overview
VPS machines are unable to run Passenger if the server type is set to Nginx (instead of Apache).
An alternative method of hosting an application under Nginx without passenger would be to run it on a stand-alone HTTP server. This must also be run on a non-privileged port. The proxy can then be enabled via the DreamHost panel.
This article lists a few simple examples of how to create a stand-alone server for Node, Python, and Ruby.
Initial configuration
Step 1 — Configure the public directory
First, configure the domain to use the public subdirectory as the primary directory for the domain. View the following article for instructions on how to adjust your site's web directory on the server.
For example, you would change it to: example.com/public
Step 2 — Run the app on a non-privileged port
Use the directions below to configure your app script to run on a non-privileged port. This would be a port between 8000 and 65535.
Ports 80 and 443 cannot be used, however, the Proxy page in the panel allows the app to run without the port number binded to the URL.
Step 3 — Configure the domain on the Proxy page
This step allows you to run the app without binding the port # to the URL.
- Visit Proxy page in the panel.
- Add the domain on which the app will run.
- Select the port # the stand-alone server will run on.
- Click Add Proxy Server....
In all the following examples, port 8002 is used.
Node.js
- Install a custom version of Node.js.
- 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.
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.
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.
Make sure you have activated your virtualenv. The first part of your command prompt changes to the name of your virtualenv.
You can then use pip to install Gunicorn.
(venv)[server]$ pip3 install gunicorn
Next, create a Python file to run the site. This example is named myapp.py.
(venv)[server]$ vim myapp.py
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])
Start Gunicorn by passing in the port # to the command.
(venv)[server]$ GUNICORN_CMD_ARGS="--bind=localhost:8002" gunicorn myapp:app
Visit the domain and you will see 'Hello, World From Gunicorn!'.
Ruby
Make .gems the default Gems directory for our user. Add the following to the .bash_profile file.
export PATH=$HOME/.gems/bin:$PATH export GEM_PATH=$HOME/.gems/
source the file to load the new settings.
[server]$ source ~/.bash_profile
Next, install the Gem.
[server]$ gem install puma
In the application directory create a config.rb file.
[server]$ vi config.rb
Add the following:
app do |env| body = 'Hello, World From Puma' [200, { 'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }, [body]] end bind 'tcp://127.0.0.1:8002'
Finally, start the server up.
[server]$ puma -C config.rb