TiddlyWeb + Uwsgi + Nginx

130 views
Skip to first unread message

Tefekkür Shamall

unread,
Mar 30, 2012, 3:49:17 AM3/30/12
to TiddlyWeb
Try to deploy TillyWiki with Nginx and UWSGi, and here is my config:

;uWSGI instance configuration
[uwsgi]

;I was trying to run uwsgi as http and it works, but nginx do not
proxing it
;then i thought that it may be mistake and try to run tilddlyweb like
cgi with uwsgi, it doesn work at all

socket = /tmp/uwsgi.sock
;http = 127.0.0.1:9002
;wsgi-file = /srv/wiki/apache.py
master = true
processes = 4
;chdir = /srv/urlyss/
touch-reload = /srv/wiki/res.txt
file = /srv/wiki/apache.py
;callable = app
harakiri = 30
buffer-size = 32768
reload-on-as = 128
cpu-affinity = 1
daemonize = /var/log/uwsgi/wiki.log


##Nginx conf for uwsgi and tiddlyweb

server { listen www.something.tk:80;
server_name www.something.tk;
return 301 http://something.tk$request_uri;
}

server {

listen something.tk:80;
server_name something.tk;

root /srv/wiki/;

error_log /var/log/nginx/errwiki.log;
access_log /var/log/nginx/accwiki.log;

location / {

include uwsgi_params;
uwsgi_pass unix://tmp/uwsgi.sock;

# uwsgi_param UWSGI_SCRIPT /srv/wiki/apache;
# uwsgi_param UWSGI_PYHOME /srv/wiki/;

# proxy_pass http://127.0.0.1:9002/;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Host $host;
# proxy_set_header X-Forwarded-Port $server_port;
# proxy_set_header HOST $host;

}
}


There is already Bad Gateway.

Please tell me what i'm doing wrong.

chris...@gmail.com

unread,
Apr 2, 2012, 10:16:44 AM4/2/12
to TiddlyWeb
On Fri, 30 Mar 2012, Tefekk�r Shamall wrote:

> Try to deploy TillyWiki with Nginx and UWSGi, and here is my config:

I've not personally had a chance to try nginx and uwsgi, so I don't
know how much help I can be. When I get back to a reasonable computer,
I'll give it a try.

In the meantime, if you're going to try to run things as CGI, then
instead of the apache.py file, you may want:

https://raw.github.com/tiddlyweb/tiddlyweb/master/index.cgi

--
Chris Dent http://burningchrome.com/
[...]

chris...@gmail.com

unread,
Apr 2, 2012, 12:33:39 PM4/2/12
to TiddlyWeb
On Mon, 2 Apr 2012, chris...@gmail.com wrote:

> On Fri, 30 Mar 2012, Tefekk�r Shamall wrote:
>
>> Try to deploy TillyWiki with Nginx and UWSGi, and here is my config:
>
> I've not personally had a chance to try nginx and uwsgi, so I don't
> know how much help I can be. When I get back to a reasonable computer,
> I'll give it a try.

Okay, got it running. Here's how (I'll copy this into the docs at
TPC[1] after composing).

I found a documentation page for how to deploy Flask applications
with nginx and uwsgi to be very useful for pointers.

http://flask.pocoo.org/docs/deploying/uwsgi/

1. Install nginx.

On my Mac this was as easy as "brew install nginx". Similar apt-get
and yum commands ought to do the trick on Debian or Fedora based
systems.

2. Install uWSGI.

There's uwsgi the protocol, and uwsgi the daemon. nginx supports the
protocol, but needs the daemon. The easiest way to install it is
with pip:

pip install uwsgi

3. Create or visit your TiddlyWeb instance:

twinstance cow
cd cow

4. Copy in apache.py

Thought called apache.py from the tiddlyweb distribution. Though
called "apache" it's actually a generic WSGI application starter.

cp <path to>/apache.py .

5. Start uwsgi daemon

uwsgi -s /tmp/uwsgi.sock -w apache:application

6. Change permissions on the socket

nginx's worker runs as nobody by default and needs to read and write
the uwsgi.sock file

sudo chown nobody /tmp/uwsgi.sock

7. Configure nginx.conf

Assuming you want tiddlyweb on / find the entry for "location /" in
the http section. Comment that out and add:

location / { try_files $uri @yourapplication; }
location @yourapplication {
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi.sock;
}

8. Start or restart nginx

9. Visit the / URL

In my nginx.conf it defaults to listening on port 8080 in the
distributed config. So if I go to

http://0.0.0.0:8080/

I get the root page of TiddlyWeb.


[1] http://tiddlyweb.peermore.com/

cdent

unread,
Apr 2, 2012, 12:39:09 PM4/2/12
to tidd...@googlegroups.com


     location / { try_files $uri @yourapplication; }
     location @yourapplication {
         include uwsgi_params;
         uwsgi_pass unix:/tmp/uwsgi.sock;
     }

 
Comparing with your version, it looks like the main differences is that you have // before tmp, not / and are not using the try_files incantation. 

Tefekkür Shamall

unread,
Apr 3, 2012, 2:54:16 AM4/3/12
to tidd...@googlegroups.com
Thank you very much, I've triyed to do as you say, and found that problem was in my /tmp/uwsgi.sock, I forgot about rights for sock file and prefered localhost-port instead, now here is my configuration, that's working for nginx uwsgi tiddlyweb.

//wiki.ini file used by uwsgi 

uWSGI instance configuration
[uwsgi]
uid = 33
gid = 33
master = true
processes = 4
touch-reload = /srv/tw/res.txt
module = apache:application
harakiri = 30
buffer-size = 32768
reload-on-as = 128
cpu-affinity = 1
daemonize = /var/log/uwsgi/wiki.log
;end of configuration

//nginx site config:

server {
        listen       chillik.tk:80;
        server_name  chillik.tk;
        root    /srv/tw/;
        error_log /var/log/nginx/errwiki.log;
        access_log /var/log/nginx/accwiki.log;
location / {
        try_files $uri @app;
        }
location @app {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:9002;
        }
}

понедельник, 2 апреля 2012 г. 22:39:09 UTC+6 пользователь cdent написал:
Reply all
Reply to author
Forward
0 new messages