WebFaction
Community site: login faq

Hi,

I'm wanting to install Nginx as a reverse proxy with an nginx.conf I can play around with myself. I've found scripts and instructions across the web and this forum but every answer hooks up uwsgi at the back and seems to use it to start the Nginx server.

I tried one of those nginx/uwsgi tutorials with the uwsgi stripped out and couldn't get it working and a straight forward Nginx compilation indicated I had directories and files missing.

The end result I'm trying to achieve is a straight forward Nginx reverse proxy that I can tweak to work with Gunicorn, Gevent and python websockets (not together, just one at a time).

Any help appreciated, thanks.

asked 04 Jul '16, 18:20

zilog8bit
271918
accept rate: 0%


Here you go; this is a stripped-down version of the Nginx+uWSGI guide which simply performs a proxy_pass to a backend webserver.

You'll first need to create a new Custom Application (listening on port) in your applications list, and then should be able to fill in the beginning variables and proceed with the following commands. I tested this on on CentOS 7 as well. Hope that helps!

# Set environment variables
APPNAME=mynginx            # Name of the Nginx Custom Application
APPPORT=12345              # Assigned port for the Nginx Custom Application
BACKENDPORT=77777          # Localhost port where backend server listens

###########################################################
# nginx 1.2.3
# original: http://nginx.org/download/nginx-1.2.3.tar.gz
###########################################################
cd $HOME/webapps/$APPNAME/src
wget 'http://mirror.ryansanden.com/uwsgi-1.2/nginx-1.2.3.tar.gz'
tar -xzf nginx-1.2.3.tar.gz
cd nginx-1.2.3
./configure \
  --prefix=$HOME/webapps/$APPNAME/nginx \
  --sbin-path=$HOME/webapps/$APPNAME/nginx/sbin/nginx \
  --conf-path=$HOME/webapps/$APPNAME/nginx/nginx.conf \
  --error-log-path=$HOME/webapps/$APPNAME/nginx/log/nginx/error.log \
  --pid-path=$HOME/webapps/$APPNAME/nginx/run/nginx/nginx.pid  \
  --lock-path=$HOME/webapps/$APPNAME/nginx/lock/nginx.lock \
  --with-http_flv_module \
  --with-http_gzip_static_module \
  --http-log-path=$HOME/webapps/$APPNAME/nginx/log/nginx/access.log \
  --http-client-body-temp-path=$HOME/webapps/$APPNAME/nginx/tmp/nginx/client/ \
  --http-proxy-temp-path=$HOME/webapps/$APPNAME/nginx/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=$HOME/webapps/$APPNAME/nginx/tmp/nginx/fcgi/
make && make install

###########################################################
# Configure Nginx
###########################################################

mkdir -p $HOME/webapps/$APPNAME/{bin,nginx/tmp/nginx/client}
ln -s $HOME/webapps/$APPNAME/nginx/sbin/nginx $HOME/webapps/$APPNAME/bin

cat << EOF > $HOME/webapps/$APPNAME/nginx/nginx.conf
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    access_log  ${HOME}/logs/user/access_${APPNAME}.log combined;
    error_log   ${HOME}/logs/user/error_${APPNAME}.log  crit;

    include mime.types;
    sendfile on;

    server {
        listen 127.0.0.1:${APPPORT};

        location / {
            proxy_pass   http://127.0.0.1:${BACKENDPORT};
        }
    }
}
EOF

###########################################################
# Make the start, stop, and restart scripts
###########################################################

cat << EOF > $HOME/webapps/$APPNAME/bin/start
#!/bin/bash

APPNAME=${APPNAME}

# Start nginx
\${HOME}/webapps/\${APPNAME}/bin/nginx
EOF

cat << EOF > $HOME/webapps/$APPNAME/bin/stop
#!/bin/bash

APPNAME=${APPNAME}

# stop nginx
kill \$(cat \${HOME}/webapps/\${APPNAME}/nginx/run/nginx/nginx.pid)
EOF

cat << EOF > $HOME/webapps/$APPNAME/bin/restart
#!/bin/bash

APPNAME=${APPNAME}

\${HOME}/webapps/\${APPNAME}/bin/stop
sleep 5
\${HOME}/webapps/\${APPNAME}/bin/start
EOF

chmod 755 $HOME/webapps/$APPNAME/bin/{start,stop,restart}

Finally, to start the application, execute $HOME/webapps/$APPNAME/bin/start

permanent link

answered 05 Jul '16, 09:12

ryans ♦♦
5.0k93160
accept rate: 43%

edited 05 Jul '16, 09:23

Really clear, thank you ryans it works perfectly. I can see how the server startup scripts work here too which looks like where I had gone wrong with the uwsgi mix in.

(05 Jul '16, 12:48) zilog8bit

To just get nginx installed and then make whatever changes you want to the config, you should be able to just pull out the nginx install portion from this post

permanent link

answered 04 Jul '16, 18:31

bmeyer71 ♦♦
1.5k3613
accept rate: 33%

That was the post I stripped the uwsgi bit out of but got an error when about missing files when trying to start the server. I've tried following the steps twice now and I still don't end up with a ~/bin/nginx file. It's quite confusing with all the uwsgi stuff intertwined with it all.

(04 Jul '16, 19:46) 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:

×186
×25
×17
×3

question asked: 04 Jul '16, 18:20

question was seen: 2,558 times

last updated: 05 Jul '16, 12:48

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 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