我有一個django應用程序設置與nginx + gunicorn +主管和它的工作正常。但我需要爲「dev.domain.com」創建一個用於分段或開發的子域。我在nginx.conf中爲我的子域添加了另一個服務器塊。但我的子域網址始終指向主域名站點。所以我改變了其他職位上建議的proxy_pass中的端口號。但由於gunicorn和supervisord我需要在「/etc/supervisord/conf.d/subdomain.conf」中爲此子域添加另一個conf文件,但是當我重新加載supervisord時,它無法啓動我的子域程序。下面是我的nginx.conf,subdomain.conf,script.sh: nginx.conf如何在以下環境中設置子域名:nginx,主管,django,gunicorn?
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_static on;
gzip_types application/x-javascript text/css text/html application/json text/css text/json;
server {
listen 80;
server_name domain_name
# no security problem here, since/is alway passed to upstream
root /home/path/to/project/base
# serve directly - analogous for static/staticfiles
location /static/ {
# if asset versioning is used
if ($query_string) {
expires max;
}
autoindex off;
root /home/path/to/static/;
}
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_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://localhost:8000/;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
server {
listen 80;
server_name subdomain_name
# no security problem here, since/is alway passed to upstream
root /home/path/to/subdomain_directory(which is different, you can say it is fully differnt project which i want to run as development project);
# serve directly - analogous for static/staticfiles
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_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://localhost:9000/;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
}
script.sh
set -e
NUM_WORKERS=4
# user/group to run as
USER=user_name
#GROUP=your_unix_group
cd /home/path/to/subdomain_base
source subdomain_virtualenv_activation
LOGFILE=log_file_path
LOGDIR=$(dirname $LOGFILE)
test -d $LOGDIR || mkdir -p $LOGDIR
exec virtualenvironment/bin/gunicorn_django -w $NUM_WORKERS \
--user=$USER --log-level=debug \
--log-file=$LOGFILE 2>>$LOGFILE
subdomain.conf
[program:programname]
directory = /home/path/to/subdomainbase/
user = user_name
command = /home/path/to/script.sh
stdout_logfile = /home/path/to/log
stderr_logfile = /home/path/to/log
我也有一個procfile,建議在gunicorn這是在基本目錄 Procfile
./manage.py runserver_plus 0.0.0.0:$PORT
好了,所以這是我的配置。請檢查我在做錯什麼。我只想將我的開發服務器作爲一個不同的項目運行,但是與子域位於同一個域下。畢竟,無論我在做什麼改變,主域名都可以正常工作。如果您需要關於此錯誤的更多信息,請告訴我。
感謝您的回覆,我曾嘗試在gunicorn腳本中添加「ADDRESS = 127.0.0.1:PORT」並重新載入supervisord,但它沒有奏效。我檢查了超級用戶日誌,有兩條消息與我的新子域應用1相關。EXIT STATUS 1:NOT EXPECTED,並在下一行2.「進入FATAL狀態,太多開始重試太快」(我不知道爲什麼它說的太多重啓我只重載了一次,請檢查是否可以得到是什麼原因造成的問題,謝謝 – 2013-03-20 08:41:00
如果你手工運行腳本(沒有supervisord),它的工作是否正確? – jjimenez 2013-03-21 11:54:05
哦,我們可以做那麼測試?我會測試同樣,並讓你知道它是否工作與否,謝謝你的回覆。 – 2013-03-22 11:58:26