python - 如何在生产环境中使用 gunicorn 和 nginx 托管 2 个 Django 应用程序
问题描述
您好,我想使用 Gunicorn 和 Nginx 托管 2 个 djagno 网站,但我不知道该怎么做这是我第一次在一个服务器和 2 个域中托管 2 个 django 网站,所以请告诉我如何托管 2 个 django 网站。这是位于 /var/www/site1 的我的 1 个文件,这是我的 2 个文件 /var/www/site2
解决方案
假设您在端口 8081 和 8082 上运行 gunicorn 实例,您有两个选择:
选项 1:子域
要使用子域通过 NGINX 进行反向代理,请参阅此答案。
http://site1.example.com/重定向到站点 1,http ://site2.example.com/ 重定向到站点 2。
NGINX 配置:
server {
listen 80;
server_name site1.example.com;
location / {
proxy_pass http://127.0.0.1:8082;
}
}
server {
listen 80;
server_name site2.example.com;
location / {
proxy_pass http://127.0.0.1:8082;
}
}
选项 2:地点
http://example.com/site1/现在重定向到站点 1 和http://example.com/site2/到站点 2。
NGINX 配置:
server {
listen 80;
server_name example.com;
location /site1/ {
proxy_pass http://127.0.0.1:8081;
}
location /site2/ {
proxy_pass http://127.0.0.1:8082;
}
}
编辑 - 选项 3:域
您也可以像选项 1 一样为不同的站点使用不同的域。
http://site1.com/重定向到站点 1,http ://site2.com/ 重定向到站点 2。
NGINX 配置:
server {
listen 80;
server_name site1.com;
location / {
proxy_pass http://127.0.0.1:8082;
}
}
server {
listen 80;
server_name site2.com;
location / {
proxy_pass http://127.0.0.1:8082;
}
}
注意:这些是最低限度的设置,可能需要额外的配置才能与您的特定服务一起使用。
推荐阅读
- azure - Azure API Manager 增加了函数缩放时的响应时间
- javascript - 在父类传递的事件处理程序中有条件地更新子组件的状态
- performance - Rails 终端命令在 12 秒后运行,为什么?
- javascript - 单击后,我的按钮有问题,停机时间
- c# - 从 C# WinForms 错误消息中提取特定信息
- java - JDBC 表创建捕获没有按我的预期出错
- scala - 在 Scala.js 中超时未来
- ruby-on-rails - Google Geochart 仅在刷新后出现
- php - SwiftMailer 不在 MessageHandler 中发送邮件
- python - 将指数拟合到范围和绘制结果并拟合