nginx redirect to gunicorn for Django or Jetty/Tomcat

Prototyping a tiny project with Django 1.4 on Ubuntu.

Want to use gunicorn and nginx for Django.

Here we go!

1.suppose the django project is already there, now install gunicorn and nginx

sudo apt-get install gunicorn nginx

2.append gunicorn to settings.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'myApplication'
    'djangorestframework',
    'gunicorn',
)

3.run application inside gunicorn

python manage.py run_gunicorn


4. append a new server in nginx configuration (/etc/nginx/nginx.conf)

sudo vi /etc/nginx/nginx.conf

http {

##...
##...
       server {
	   listen          80;
	   server_name     192.168.85.172;  #yousite.com
	   #access_log      /var/log/your_website_log main;

	    location / {
		 proxy_pass http://localhost:8000/;
	         proxy_redirect  off;
	    }
	}
}

Note: Here 192.168.85.172 is the local ip of the testing server. 'server_name' is 'localhost' by default, but I could't make it bind to port 80 successfully until I changed it as such. If I don't change 'server_name', I have to bind to other port (e.g 8001) on my Ubuntu 12.04

Now access nginx http://localhost/admin is actually redirected to django on gunicornhttp://localhost:8000/admin


5. if you're running J2EE on Jetty/Tomcat...

just change change the proxy_pass primitive to such as 'proxy_pass http://localhost:8080/;' after starting jetty/tomcat
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值