在Ubuntu 10.04上使用Nginx自动使用域名启动Tornado
我已经成功设置了 nginx.conf 文件,它看起来像这样:
root www www;
worker_processes 1;
worker_rlimit_nofile 8192;
events {
worker_connections 8000;
accept_mutex off;
}
error_log logs/error.log;
pid logs/nginx.pid;
http {
# Set the mime-types
include mime.types;
# And the fallback mime-type
default_type application/octet-stream;
# Format for our log files
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# Click tracking!
access_log logs/access.log main;
# ~2 seconds is often enough for HTML/CSS, but connections in
# Nginx are cheap, so generally it's safe to increase it
keepalive_timeout 5;
# You usually want to serve static files with Nginx
sendfile on;
tcp_nopush on; # off may be better for Comet/long-poll stuff
tcp_nodelay off; # on may be better for Comet/long-poll stuff
# Enable Gzip
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types text/html text/plain text/xml application/xml application/xml+rss text/css text/javascript application/javascript application/json;
gzip_static on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
server {
# listen 80 default deferred; # for Linux
# listen 80 default accept_filter=httpready; # for FreeBSD
listen 80 default;
# e.g. "localhost" to accept all connections, or "www.example.com"
# to handle the requests for "example.com" (and www.example.com)
server_name _;
# Path for static files
root /srv/www/example.com/public_html/src/static;
expires 1M;
# Static assets
location ~* ^.+\.(manifest)$ {
expires -1D;
root /srv/www/example.com/public_html/src/;
access_log /srv/www/example.com/logs/static.logs;
}
location ~* ^.+\.(ico|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
# Only set expires max IFF the file is a static file and exists
if (-f $request_filename) {
expires max;
root /srv/www/example.come/public_html/src/static;
access_log /srv/www/example.com/logs/static.logs;
}
}
}
}
我对 nginx 文件的问题是: 1)我想用域名托管我的应用程序:www.example.com,我应该更改 nginx.conf 文件的哪一行?
我的 nginx.conf 文件与 app.py 位于同一文件夹中。
2)当我尝试通过输入 /etc/init.d/nginx start 来启动 nginx 时,收到以下错误消息:
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 did any configuration to the nginx.conf file found at /etc/nginx 我对这部分的问题是: 3)如何修复错误? 4)如何自动启动nginx?
我尝试通过键入来运行我的龙卷风应用程序 蟒蛇应用程序.py 然后我导航到 http://xxx.xx.xxx.xxx:8888 和我的应用程序工作正常。
但是,如果我关闭终端(终止进程),我的龙卷风应用程序将不再活动。
我的问题是: 5)如何自动启动龙卷风应用程序? 6) 如何在域名上运行龙卷风?
感谢大家的耐心等待。
此致。
I've managed to set up my nginx.conf file and it looks like this:
root www www;
worker_processes 1;
worker_rlimit_nofile 8192;
events {
worker_connections 8000;
accept_mutex off;
}
error_log logs/error.log;
pid logs/nginx.pid;
http {
# Set the mime-types
include mime.types;
# And the fallback mime-type
default_type application/octet-stream;
# Format for our log files
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# Click tracking!
access_log logs/access.log main;
# ~2 seconds is often enough for HTML/CSS, but connections in
# Nginx are cheap, so generally it's safe to increase it
keepalive_timeout 5;
# You usually want to serve static files with Nginx
sendfile on;
tcp_nopush on; # off may be better for Comet/long-poll stuff
tcp_nodelay off; # on may be better for Comet/long-poll stuff
# Enable Gzip
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types text/html text/plain text/xml application/xml application/xml+rss text/css text/javascript application/javascript application/json;
gzip_static on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
server {
# listen 80 default deferred; # for Linux
# listen 80 default accept_filter=httpready; # for FreeBSD
listen 80 default;
# e.g. "localhost" to accept all connections, or "www.example.com"
# to handle the requests for "example.com" (and www.example.com)
server_name _;
# Path for static files
root /srv/www/example.com/public_html/src/static;
expires 1M;
# Static assets
location ~* ^.+\.(manifest)$ {
expires -1D;
root /srv/www/example.com/public_html/src/;
access_log /srv/www/example.com/logs/static.logs;
}
location ~* ^.+\.(ico|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
# Only set expires max IFF the file is a static file and exists
if (-f $request_filename) {
expires max;
root /srv/www/example.come/public_html/src/static;
access_log /srv/www/example.com/logs/static.logs;
}
}
}
}
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?
My nginx.conf file is found in the same folder as app.py.
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?
4) How do i start nginx automatically?
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?
6) How do i run tornado on a domain name?
Thank you all for your kind patience.
Best Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1) 更改
服务器名称
。2) 您可能正在运行 Apache。
3)停止服务(使用类似
service httpd stop
),然后启动nginx。4) 尝试以下命令:
5) 查看使用 supervisor 运行 python 应用程序
6) 查看 nginx wiki 了解有关反向代理的信息; nginx 处理对域的请求并将这些请求传递到您的tornado 后端。
1) Change the
server_name
.2) You probably have Apache running.
3) Stop the service (using something like
service httpd stop
) and then start nginx.4) Try the following commands:
5) Look at using supervisor for running python apps
6) Check out the nginx wiki for information on reverse proxying; nginx handles requests to the domain and passes those requests to your tornado backend.
关于错误信息:使用Ubuntu 11.10时出现同样的问题,似乎Opera占用了80端口,所以只需修改该值即可。
about the error message: the same problem when using Ubuntu 11.10 , it seems that Opera occupy the port 80, so just modify the value.