【问题标题】:Starting Tornado with Nginx on Ubuntu 10.04 automatically with domain name在 Ubuntu 10.04 上使用 Nginx 自动使用域名启动 Tornado
【发布时间】:2011-07-13 21:54:00
【问题描述】:

我已经成功设置了我的 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 时,我收到以下错误消息:

错误信息:

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.

我没有对 /etc/nginx 中的 nginx.conf 文件进行任何配置 我对这部分的问题是: 3)我如何修复错误? 4) 如何自动启动nginx?

我尝试通过键入来运行我的 Tornado 应用程序 蟒蛇应用程序.py 比我导航到 http://xxx.xx.xxx.xxx:8888 ,我的应用程序正常工作。

但是,如果我关闭终端(终止进程),我的 tornado 应用程序将不再活动。

我的问题是: 5)我如何自动启动龙卷风应用程序? 6) 如何在域名上运行 tornado?

感谢大家的耐心等待。

最好的问候。

【问题讨论】:

  • 如果您还没有这样做,请尝试将其交叉发布到 ServerFault
  • 您需要提供更多关于您工作环境的信息;例如。你安装的是哪个版本的linux,哪个版本的nginx/python等

标签: nginx ubuntu-10.04 tornado


【解决方案1】:

关于错误信息:使用Ubuntu 11.10时同样的问题,好像Opera占用了80端口,修改一下即可。

【讨论】:

    【解决方案2】:

    1) 更改server_name

    2) 您可能正在运行 Apache。

    3) 停止服务(使用 service httpd stop 之类的东西),然后启动 nginx。

    4) 尝试以下命令:

    $ chkconfig httpd off
    $ chkconfig --add nginx
    $ chkconfig nginx on
    $ service nginx start
    

    5) 看看使用supervisor 运行python 应用程序

    6) 查看nginx wiki 以获取有关reverse proxying 的信息; nginx 处理对域的请求并将这些请求传递到您的 tornado 后端。

    【讨论】:

      猜你喜欢
      • 2011-06-22
      • 2013-02-04
      • 1970-01-01
      • 2011-06-23
      • 1970-01-01
      • 1970-01-01
      • 2018-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多