Your nginx.conf file either needs to be in the directory that ngnix is configured to look in (depending on how it is configured (default if compiled from source and you did not change any options /usr/local/nginx/conf/nginx.conf) or you can specify the config file when you start nginx (i.e. nginx -c /path/to/nginx.conf)
There are a number of sample init scripts for nginx look here:
http://wiki.nginx.org/Configuration#Init_Scripts
As for your tornado app, project.py probably should not be inside the templates directory; you should look at the demos that come with tornado. To answer your question, you would start your app the same way you would before you added nginx to the mix. (i.e. python myapp.py)
If you search the archives of this group you will find both example nginx configurations as well as configurations for supervisord (one of the recommended ways of starting your tornado app processes).
Andrew
> 2) I've installed Nginx and started it based on the instructions
> here : http://library.linode.com/web-servers/nginx/installation/ubuntu-10.04-lucid
I'd not follow those instructions. Instead you should use the Nginx
PPA documented on the Nginx wiki:
basically this:
sudo aptitude purge nginx
sudo add-apt-repository ppa:nginx/stable
sudo aptitude update
sudo aptitude install nginx
This will give you the most recent, stable version of Nginx. The
official Ubuntu version is ancient and there's little reason to build
from source unless you need a customized build.
> My questions are: Where does my nginx configuration file go ?
It goes in /etc/nginx. The main file is nginx.conf, but it can include
other files. The key part you'll need is something like:
server {
root /path/to/static/files;
location / {
try_files $uri @tornado;
}
location @tornado {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:5000;
}
}
> Within
> the src/ folder? After configuring Nginx, how do I start my Tornado
> project?
Start Nginx, start your Tornado application
python --port=5000 myapp.py
and test. Next you'll want to look into using supervisord or similar
to manage your Tornado process, but you need to get Nginx and Tornado
tested first before you worry about that.
Regards,
Cliff
>
> server {
> root /path/to/static/files;
>
> location / {
> try_files $uri @tornado;
> }
>
> location @tornado {
> proxy_set_header Host $host;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> proxy_pass http://127.0.0.1:5000;
> }
> }
>
>
> does " location / " refer to the directory location of my Tornado
> project? As in the location of
> project.py ?
No, it's a URI. http://mysite.com/ <-- that trailing slash is the "/"
in the location directive.
I should point out that Nginx does not care about the location of your
Tornado application. It will not be referencing any Tornado files
directly. Nginx and Tornado will be communicating via HTTP over your
loopback interface.
In fact, I recommend putting your static resources (images, css, etc) in
a directory completely separate from your Tornado application. This way
a misconfiguration of Nginx will be less likely to result in someone
gaining access to sensitive information.
> What does try_files $uri @tornado do ?
It tries first to locate a static file (such as css, js, jpg, etc),
using the $uri relative to the $document_root, and if that fails, passes
the request to the @tornado location, which in turn hands it over to
Tornado to handle.
> What does location @tornado do?
The @ symbol means a "named" location, that is, one that cannot be
referenced directly from the client's browser. This location is simply
to encapsulate the proxying directives into a tidy location.
Regards,
Cliff
There are a number of sample init scripts for nginx look here:
http://wiki.nginx.org/Configuration#Init_Scripts
As for your tornado app, project.py probably should not be inside the templates directory; you should look at the demos that come with tornado. To answer your question, you would start your app the same way you would before you added nginx to the mix. (i.e. python myapp.py)
If you search the archives of this group you will find both example nginx configurations as well as configurations for supervisord (one of the recommended ways of starting your tornado app processes).
Andrew
On Feb 7, 2011, at 10:33 AM, yupyup1234 wrote:
-j
On Fri, Mar 11, 2011 at 4:40 AM, TornadoRocks <ye.e...@gmail.com> wrote:
> My questions for nginx file is:
> 1) I would want to host my application with the domain name :
> www.example.com, which line of the nginx.conf file do i change?
server_name
> 2) When I was trying to start nginx by typing /etc/init.d/nginx start, I
> received the following error message:
> Error Message:
> Starting nginx: [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in
> use)
> [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
> [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
> [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
> [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
> [emerg]: still could not bind()
> nginx.
> I have not done any configuration to the nginx.conf file found at /etc/nginx
> My questions for this part are:
> 3) How do i fix the error?
It's already running. kill it.
> 4) How do i start nginx automatically?
This is more of an ubuntu question. Google for "start service at boot
ubuntu". I can't remember which command it is to do this but it's
very simple.
> I've tried running my Tornado app by typing
> python app.py
> Than I navigate to http://xxx.xx.xxx.xxx:8888 , and my app works correctly.
> However, should I close my terminal ( killing the process ) , my tornado app
> is no longer active.
> My question here is:
> 5) how do i start tornado app automatically?
use supervisord to start it.
-j
--
The Christian ideal has not been tried and found wanting;
it has been found difficult and left untried – G. K. Chesterton
This is wrong. Nginx is a completely separate program unrelated to
Tornado. You need to configure /etc/nginx/nginx.conf.
Cliff
Not required (you could put all the config in a single file), but
usually recommended.
> If so, what are the contents required for the config file
> in sites-enabled ?
It depends. There's no "recipe" for a generic website. At the very
least you'll need a server section with directives to proxy to your
Tornado app, but if I were you, I'd at least become somewhat familiar
with Nginx (try serving some static files before moving on to more
complex tasks). There's lots of examples and documentation here:
Cliff
Instead we configure a separate config for each tornado project
isntance and then have the /etc/nginx config include those.
-j
--