我开始使用 Django 开发一个新网站。为了进行实际测试,我想在 Synology DS212J NAS 上运行它。 按照官方 Synology 指南,我安装了 ipkg 及其 mod_wsgi 软件包。 下一步:按照标准教程,我创建了一个 virtualenv 并在其中安装了 Django。打开一个新项目并将以下设置调整为:https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-16-04 我可以使用 manage.py 从 Django 访问“Hello World”站点
正如建议的那样,我想通过 NAS 上的 apache 服务器交换 manage.py。所以我想我应该去编辑 apache 配置文件,例如定义虚拟主机... 但是我无法本地化它的文件,因为与其他指南相比,它们似乎在 DSM6(我使用的)上移动了。
我需要在 Synology 教程中的哪里输入值?
由于我对这个主题还很陌生,我是否需要特别加载 Apache 的 mod_wsgi 模块?如果在哪里?
使用wsgi的基本模式而不是守护进程模式是个好主意吗?我不确定稍后的开发中会使用哪些 Django 模块...
感谢支持!
最佳答案
激活 python 3 包和网站
在 webstation> general settings> main server http enable nginx
在 Control Panel> Network> DSM Settings> Enable Custom Domain: "test"
(这将允许我们通过输入 test.local 来访问 nas,并简化稍后的任务。)
在 control panel> terminal and smtp
中启用 ssh 连接
在我们的案例“test.synology.me”中,我们使用synology的ddns服务进行外部访问
在 control panel> security> certificate
:我们使用 Let's Encrypt 生成 ssl 证书
通过ssh连接到nas
取得root权限sudo -i
安装virtualenv:easy_install virtualenv
我们设置虚拟环境:virtualenv -p python3 flasktest
Flask 和 Gunicorn 已安装:
pip install flask gunicorn
我们创建我们的网络应用程序,文件:init.py
我们使用 Gunicorn 启动 Web 应用程序:
gunicorn --certfile /usr/syno/etc/certificate/system/default/cert.pem --keyfile /usr/syno/etc/certificate/system/default/privkey.pem -b 127.0 .0.1: 5000 app: app
在 /etc/nginx/sites-enabled
我们创建一个服务器配置文件,我们将使用 nginx 作为代理,在我们的例子中该文件将是flasktest.conf
Flasktest.conf 文件:
` 服务器{
listen 443 ssl http2;
listen [::]:443 ssl http2;
gzip on;
server_name test.synology.me;
location / {
proxy_pass https://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_log /volume1/projects/flasktest/logs/error.log;
access_log /volume1/projects/flasktest/logs/acess.log;
} `
打开control panel port> external access> router configuration> create> integrate application> enable the check box for webstation and apply
我们检查服务器文件是否输入命令 nginx -t
我们正在重新启动 nginx synoservicecfg --restart nginx
您现在可以从外部通过 https ** https://test.synology.me** 访问您的 Python Web 应用程序
更多信息... 要永久结束并访问您的应用程序(如果您能够重新启动、崩溃)...您可以创建一个脚本来重新启动gunicorn,否则网站将接管其他地方,如果您在本地输入 ip nas,您将看不到您的网站python中的apps,因为我们没有在本地修改主配置文件/etc/nginx/nginx.conf,所以这是将显示的网站默认的index.html页面。
示例:
cd / volume1 / projects / flasktest
source bin / activate
gunicorn --certfile /usr/syno/etc/certificate/system/default/cert.pem --keyfile /usr/syno/etc/certificate/system/default/privkey.pem -b 127.0.0.1:5000 app: app
</ dev / null 2> & 1 &
此方法在其他Python框架中找到
关于python - Synology DS 上的 Apache 配置,用于 mod_wsgi/Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54164165/