0

nginx + gunicorn +supervisorを使用してdjangoアプリをセットアップし、正常に動作しています。ただし、「dev.domain.com」のようなステージングまたは開発用のサブドメインを作成する必要があります。サブドメイン用にnginx.confに別のサーバーブロックを追加しました。しかし、私のサブドメインのURLは常にメインドメインサイトを指していた。そのため、他の投稿で提案されているように、proxy_passのポート番号を変更しました。しかし、gunicornとsupervisordが原因で、このサブドメインの別のconfファイルを「/etc/supervisord/conf.d/subdomain.conf」に追加する必要がありましたが、supervisoredをリロードすると、サブドメインプログラムを開始できません。以下は私のnginx.conf、subdomain.conf、script.shです: nginx.conf

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

さて、これらは私の構成です。私が間違ったことをしているところを確認してください。開発サーバーを別のプロジェクトとして実行したいのですが、サブドメインと同じドメインで実行します。このすべての後、私が行っている変更が何であれ、メインドメインは同じプロセスで正常に機能しています。このエラーについてさらに情報が必要な場合はお知らせください。

4

1 に答える 1

1

編集

私はあなたの投稿をもう一度読んでいます.GunicornスクリプトでADDRESSを設定する必要はありませんか? gunicorn はデフォルトでポート 8000 を使用しますが、サブドメインが同じポートを使用しようとしている可能性がありますか?

編集終了

あなたがやりたいように、nginx、gunicorn、およびスーパーバイザーで実行されている2つのDjangoアプリケーションがあります(同じではありませんが、非常に似ています。2つのドメインと1つのサブドメインがあります)。あなたの間違いがどこにあるのかわかりません.nginxの設定にあるに違いないと思います。多分「ルート」ライン?

「supervisorctl」コマンドを使用して起動しようとしたときに、supervisord がエラーを返すかどうかを見たことがありますか?

私の設定をお見せして比較してみてください:

nginx用に 2 つの .conf ファイルがあります。

domain1.conf:

server {
    listen  80;
    server_name  domain1.net;
    return 301 $scheme://www.domain1.net$request_uri;    
}

server {
    listen 80;
    server_name www.domain1.net;
    access_log /var/log/nginx/domain1.log;

    location /static {
        alias /var/www/domain1/media/;
        autoindex on;
        access_log off;
    }

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Forwarded-For  $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_connect_timeout 10;
        proxy_read_timeout 10;
        proxy_pass http://127.0.0.1:8000/;
    }

}

および domain2.conf:

server {
    listen 80;
    server_name subdomain.domain2.es;
    access_log /var/log/nginx/domain2.log;

    location /static {
        alias /var/www/dev/domain2/domain2/static/;
        autoindex on;
        access_log off;
    }

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Forwarded-For  $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_connect_timeout 10;
        proxy_read_timeout 10;
        proxy_pass http://127.0.0.1:8005/;
    }

}

私の 2 つのgunicor スクリプトは同じで、そのうちの 1 つのパスと ADDRESS を変更するだけです。

#!/bin/bash
set -e
LOGFILE=/var/log/gunicorn/domain1.log
LOGDIR=$(dirname $LOGFILE)
NUM_WORKERS=1
# user/group to run as
USER=user
GROUP=user
ADDRESS=127.0.0.1:8005
cd /var/www/dev/domain1
source /path/to/venv/domain1/bin/activate
test -d $LOGDIR || mkdir -p $LOGDIR
exec gunicorn_django -w $NUM_WORKERS --bind=$ADDRESS \
  --user=$USER --group=$GROUP --log-level=debug \
  --log-file=$LOGFILE 2>>$LOGFILE

私の 2 つのスーパーバイザースクリプトも同じです。

[program:domain1]
directory = /var/www/dev/domain1/
user = user
command = /path/to/bin/gunicorn_domain1.sh
stdout_logfile = /var/log/nginx/domain1.log
stderr_logfile = /var/log/nginx/domain1.log

これがお役に立てば幸いです。

于 2013-03-18T17:11:08.973 に答える