2012年8月21日 星期二

如何讓Nginx也能同時啟動一個以上的網站

由於工作需要在同一台電腦上啟動2個web server服務

所以研究了一下,終於找到簡單可行的方法 :D

 

1. 首先編輯以下Nginx設定,新增以下文字

假設我們新的網站名稱是huajiang (可根據您的需要提換,但所有粗體字設定必須一致!)

$ sudo /etc/nginx/sites-enabled/default

 

server {
    listen   8888; ## listen for ipv4; this line is default and implied
 

    root /usr/share/nginx/huajiang;
    index index.html index.htm;

    server_name huajiang.gov;

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

    location / {
        include uwsgi_params;
        uwsgi_pass unix:///tmp/huajiang.sock;
        uwsgi_param UWSGI_PYHOME /var/www/huajiang;
        uwsgi_param UWSGI_CHDIR /var/www/huajiang;
        uwsgi_param UWSGI_SCRIPT index;
    }
}

2. sudo nano /etc/uwsgi-python/apps-enabled/huajiang.xml (一定要建立這個檔案!!!)

<uwsgi>
  <socket>/tmp/huajiang.sock</socket>
  <master/>
  <pythonpath>/usr/lib/pymodules/python2.6</pythonpath>
  <pythonpath>/usr/local/lib/python2.6/dist-packages</pythonpath>
  <limit-as>512</limit-as>
  <processes>8</processes>
  <gid>www-data</gid>
  <uid>www-data</uid>
  <memory-report/>
  <vhost/>
  <no-site/>
</uwsgi>
 

3. sudo mkdir /var/www/huajiang

4. 把新的網站的程式碼放到以上的路徑底下

5. sudo service nginx restart

6. sudo service uwsgi-python restart

7. 打開瀏覽器連到這台機器,例如 http://localhost:8888

新的網站就生效了~

P.S. 如果您開啟Nginx的log出現以下訊息:

connect() to unix:///tmp/huajiang.sock failed (111: Connection refused) while connecting to upstream, client: 192.168.1.21, server: huajiang.gov, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///tmp/huajiang.sock:", host: "192.168.1.26:8888"

可以試試步驟2這個程序,重啟uwsgi服務時,就會在/tmp路徑建立sock檔案

就不會一直出現Bad Gateway這個訊息了

 

相關文章 :

6 意見:

匿名 提到...

Hi there! I just would like to give a huge thumbs up for the nice info you’ve got
right here on this post. I will likely be coming back to your weblog for more soon.


Feel free to visit my web page colgate country showdown 2008 winner

匿名 提到...

Hey! I just wish to give an enormous thumbs up for the good information you have got here on this
post. I will be coming back to your blog for more soon.

my weblog :: how to install ikea cabinets

匿名 提到...

Howdy! I just want to give a huge thumbs up for the great information
you will have here on this post. I can be coming back to your
blog for more soon.

Visit my weblog: basic music theory test online

旅行社 提到...

哇@_@都看不懂阿 哈哈

旅遊 提到...

謝謝分享

ThaoCode 提到...

thank !!tai iwin . game iwin

張貼留言

Related Posts with Thumbnails
by TemplatesForYou-TFY
SoSuechtig