我有一个带有 nginx+gunicorn+supervisor 的 django 应用程序设置,并且工作正常。但我需要创建一个子域用于分期或开发,如“dev.domain.com”。我在 nginx.conf 中为我的子域添加了另一个服务器块。但是我的子域 url 总是指向主域站点。所以我按照其他帖子的建议更改了 proxy_pass 中的端口号。但由于 gunicorn 和 supervisord,我需要在“/etc/supervisord/conf.d/subdomain.conf”中为此子域添加另一个 conf 文件,但是当我重新加载 supervisord 时,它无法启动我的子域程序。下面是我的 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;
}
}
}
脚本.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
子域.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
好的,这些是我的配置。请检查我在哪里做错了。我只想将我的开发服务器作为不同的项目运行,但在与子域相同的域下。毕竟,无论我在做什么更改,主域都可以在相同的过程中正常工作。如果您需要有关此错误的更多信息,请告诉我。