我已经竭尽全力解决这个问题,希望能得到一些帮助
我希望在一个DigitalOcean小滴上托管两个Django项目。 在遵循this guide之后,我可以毫无问题地托管一个站点,但是我只是想不出一种方法来使两个站点同时工作。 当前example.com有效,而example2.com的问题是正在使用project1设置模块-project1.settings。我需要它使用项目目录中的project2.settings模块,我不知道该怎么做。
我的project1的gunicorn.socket文件:
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
我的project2的gunicorn.socket文件:
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/project2.gunicorn.sock
[Install]
WantedBy=sockets.target
我对project1的gunicorn.service文件:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=rain
Group=www-data
WorkingDirectory=/home/rain/rv/project1-web
ExecStart=/home/rain/rv/rv-env/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
project1.wsgi:application
[Install]
WantedBy=multi-user.target
我认为另一个项目应该有另一个服务文件,所以我创建了project2.gunicorn.service:
[Unit]
Description=gunicorn daemon
Requires=project2.gunicorn.socket
After=network.target
[Service]
User=rain
Group=www-data
WorkingDirectory=/home/rain/rv/project2-web
ExecStart=/home/rain/rv/rv-env/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
project2.wsgi:application
[Install]
WantedBy=multi-user.target
我的nginx网站可用于project1的文件:
server {
server_name example.com;
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/rain/rv/project1-web;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
server_name www.example.com;
charset utf-8;
return 301 https://example.com$request_uri;
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name example.com www.example.com;
return 404; # managed by Certbot
}
以及project2的另一个服务器块:
server {
server_name example2.com;
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/rain/rv/project2-web;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/project2.gunicorn.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example2.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example2.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
server_name www.example2.com;
charset utf-8;
return 301 https://example2.com$request_uri;
}
server {
if ($host = www.example2.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example2.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name example2.com www.example2.com;
return 404; # managed by Certbot
}