Created
September 19, 2012 21:29
-
-
Save mehmetkose/3752393 to your computer and use it in GitHub Desktop.
Linode VPS üzerinde Nginx, Supervisord, Tornado Yapılandırması | Dosyalar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#mehmetkose.org/linode-uzerinde-nginx-supervisord-tornado-yapilandirmasi.html | |
import tornado.ioloop | |
from tornado.options import define, options, logging | |
import tornado.web | |
define("port", default=8888, help="run on the given port", type=int) | |
settings = { | |
"debug": True, | |
} | |
server_settings = { | |
"xheaders" : True, | |
} | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write("Hello, Linode") | |
def main(): | |
tornado.options.parse_command_line() | |
logging.info("Starting Tornado web server on http://localhost:%s" % options.port) | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
], **settings) | |
application.listen(options.port, **server_settings) | |
tornado.ioloop.IOLoop.instance().start() | |
if __name__ == "__main__": | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user nginx; | |
worker_processes 1; | |
error_log /var/log/nginx/error.log; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
use epoll; | |
} | |
http { | |
# Enumerate all the Tornado servers here | |
upstream frontends { | |
server 127.0.0.1:8888; | |
} | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
access_log /var/log/nginx/access.log; | |
keepalive_timeout 65; | |
proxy_read_timeout 200; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
gzip on; | |
gzip_min_length 1000; | |
gzip_proxied any; | |
gzip_types text/plain text/html text/css text/xml | |
application/x-javascript application/xml | |
application/atom+xml text/javascript; | |
# Only retry if there was a communication error, not a timeout | |
# on the Tornado server (to avoid propagating "queries of death" | |
# to all frontends) | |
proxy_next_upstream error; | |
server { | |
listen 80; | |
# Allow file uploads | |
client_max_body_size 50M; | |
location static/ { | |
root /srv/www/project/static/; | |
if ($query_string) { | |
expires max; | |
} | |
} | |
location = /favicon.ico { | |
rewrite (.*) /static/favicon.ico; | |
} | |
location = /robots.txt { | |
rewrite (.*) /static/robots.txt; | |
} | |
location / { | |
proxy_pass_header Server; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Scheme $scheme; | |
proxy_pass http://frontends; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash -e | |
SUPERVISORD=/usr/local/bin/supervisord | |
PIDFILE=/tmp/supervisord.pid | |
OPTS="-c /etc/supervisord.conf" | |
test -x $SUPERVISORD || exit 0 | |
. /lib/lsb/init-functions | |
export PATH="${PATH:+$PATH:}/usr/local/bin:/usr/sbin:/sbin" | |
case "$1" in | |
start) | |
log_begin_msg "Starting Supervisor daemon manager..." | |
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $SUPERVISORD -- $OPTS || log_end_msg 1 | |
log_end_msg 0 | |
;; | |
stop) | |
log_begin_msg "Stopping Supervisor daemon manager..." | |
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE || log_end_msg 1 | |
log_end_msg 0 | |
;; | |
restart|reload|force-reload) | |
log_begin_msg "Restarting Supervisor daemon manager..." | |
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE | |
start-stop-daemon --start --quiet --pidfile /var/run/sshd.pid --exec $SUPERVISORD -- $OPTS || log_end_msg 1 | |
log_end_msg 0 | |
;; | |
*) | |
log_success_msg "Usage: /etc/init.d/supervisor | |
{start|stop|reload|force-reload|restart}" | |
exit 1 | |
esac | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- conf -*- | |
[include] | |
files = *.supervisor | |
[supervisord] | |
[supervisorctl] | |
serverurl = unix://supervisord.sock | |
[unix_http_server] | |
file = supervisord.sock | |
[rpcinterface:supervisor] | |
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface | |
[program:main] | |
process_name = main-%(process_num)s | |
command = python /srv/www/project/main.py | |
--port=%(process_num)s | |
--log_file_prefix=%(here)s/logs/%(program_name)s-%(process_num)s.log | |
numprocs = 4 | |
numprocs_start = 8888 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment