Skip to content

Instantly share code, notes, and snippets.

@cwgem
Created January 24, 2014 21:16
Show Gist options
  • Select an option

  • Save cwgem/8606637 to your computer and use it in GitHub Desktop.

Select an option

Save cwgem/8606637 to your computer and use it in GitHub Desktop.
Testing nginx proxying
user deploy deploy;
worker_processes 8;
worker_rlimit_nofile 10240;
pid /var/run/nginx.pid;
events {
worker_connections 8192;
use epoll;
}
http {
## Basic reverse proxy server ##
upstream python {
server 127.0.0.1:9000;
}
server {
listen 127.0.0.1:80;
server_name localhost;
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/www.example.access.log main;
error_log /var/log/nginx/www.example.error.log;
root /home/blah/public;
index index.html index.htm;
## send request back to python server ##
location / {
proxy_pass http://python;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
#!/usr/bin/python
import time
import BaseHTTPServer
HOST_NAME = 'localhost'
PORT_NUMBER = 9000
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s):
"""Respond to a GET request."""
s.send_response(200)
s.send_header("Content-type", "text/html")
s.end_headers()
s.wfile.write("<html><head><title>Title goes here.</title></head>")
s.wfile.write("<body>")
s.wfile.write("<p>GET: You accessed path: %s</p>" % s.path)
s.wfile.write("</body></html>\n")
if __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment