2014-07-05 61 views
0

我想部署我的Tornado應用程序與Nginx作爲代理。我想在Ramnode VPS(512 CVZ),其配置爲運行此:無法與nginx反向代理部署龍捲風,沒有錯誤顯示

  • 512MB RAM
  • 512MB VSwap
  • 2 CPU核心接入
  • 120GB SSD緩存的硬盤空間
  • 的1Gbps港口

我現在不使用主管,我手動啓動龍捲風過程的四個實例:

sudo python /home/magneto/pricechase/main.py --port=8000 & 
sudo python /home/magneto/pricechase/main.py --port=8001 & 
sudo python /home/magneto/pricechase/main.py --port=8002 & 
sudo python /home/magneto/pricechase/main.py --port=8003 & 

,我可以在pricechase.in:8000現在訪問該網站pricechase.in:8003

我創建了一個新的用戶nginx,給權限到我的項目目錄:

sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx 
sudo chown -R nginx:nginx /home/magneto/pricechase/ 

以下是我的項目的conf文件,位於/etc/nginx/sites-enabled/pricechase.in

user nginx; 
worker_processes 5; 

error_log /var/log/nginx/error.log; 

pid /var/run/nginx.pid; 

events { 
    worker_connections 1024; 
    use epoll; 
} 

http{ 

    proxy_next_upstream error; 

    upstream tornadoes { 
     server 127.0.0.1:8000; 
     server 127.0.0.1:8001; 
     server 127.0.0.1:8002; 
     server 127.0.0.1:8003; 
    } 

    include /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    access_log /var/log/nginx/access.log; 

    keepalive_timeout 65; 
    proxy_read_timeout 200; 
    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    gzip on; 
    gzip_min_length 1000; 
    gzip_proxied any; 
    gzip_types text/plain text/html text/css text/xml 
       application/x-javascript application/xml 
       application/atom+xml text/javascript; 


    server { 
     listen 80; 
     server_name pricechase.in www.pricechase.in; 

     location /static/ { 
      root /home/magneto/pricechase/static; 
      if ($query_string) { 
       expires max; 
      } 
     } 
     location/{ 
      proxy_pass_header Server; 
      proxy_set_header Host $http_host; 
      proxy_redirect off; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header X-Scheme $scheme; 
      proxy_pass http://tornadoes; 
     } 
    } 
} 

當我嘗試重新啓動nginx se起動轉矩我得到以下錯誤:

Restarting nginx: nginx: [emerg] unknown directive "user" in /etc/nginx/sites-enabled/pricechase.in:1 
nginx: configuration file /etc/nginx/nginx.conf test failed 

由於回答顯示here,我評論在/etc/nginx/nginx.conf以下行:

# include /etc/nginx/sites-enabled/*; 

現在,我可以啓動/重新啓動。然而,當我在pricechase.in型,它沒有打開網站。它不能夠也訪問靜態文件,例如:http://pricechase.in/static/css/tooltipster.css它位於/home/magneto/pricechase/static/css/tooltipster.css

以下是/etc/nginx/nginx.conf內容:

user www-data; 
worker_processes 4; 
pid /var/run/nginx.pid; 

events { 
    worker_connections 768; 
    # multi_accept on; 
} 

http { 

    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 
    # server_tokens off; 

    # server_names_hash_bucket_size 64; 
    # server_name_in_redirect off; 

    include /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log; 

    gzip on; 
    gzip_disable "msie6"; 

    # gzip_vary on; 
    # gzip_proxied any; 
    # gzip_comp_level 6; 
    # gzip_buffers 16 8k; 
    # gzip_http_version 1.1; 
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 

    ## 
    # Virtual Host Configs 
    ## 

    include /etc/nginx/conf.d/*.conf; 
    # include /etc/nginx/sites-enabled/*; 
    # include /etc/nginx/sites-enabled/pricechase.in; 
} 
  • 如何調試呢?
  • 爲什麼它不記錄任何錯誤?我檢查訪問和錯誤日​​志(位於/var/log/nginx/
  • 對nginx配置文件的任何提示/改進?
  • 如果我理解正確/etc/nginx/nginx.conf就像是一個基本模板,並且我需要的任何其他主機的所有常用配置都應包含在此中,對不對?
  • 如果我想添加另一個域並服務於不同的龍捲風實例,我想我必須在sites-enabled中添加新的conf,但是會有衝突嗎?例如,我想http://abc.xyz.com服務位於/home/magneto/bloghttp://pqrs.com靜態內容端口8005的過程中起到龍捲風8008
+0

我將'/ etc/nginx/sites-enabled/pricechase.in'移至'etc/nginx/nginx.conf'並按預期工作。不知道這是我應該做的。 – avi

回答

1

在配置片段網站啓用只應該包括「HTTP」塊內的部分;其他部分只能出現在頂層的nginx.conf中。