【问题标题】:Python + Django run under a different user on apache2 (httpd), RedhatPython + Django 在 apache2 (httpd)、Redhat 上的不同用户下运行
【发布时间】:2013-09-10 07:55:42
【问题描述】:

我有一个绑定到 Red hat 上的 httpd (apache2) 的 django 应用程序,它运行良好,但是我想在与 apache 不同的用户名下运行它,所以如果它写入文件系统,文件的所有者应该是新用户。我正在寻找实现这一目标的解决方案。

我尝试使用 httpd-itk(在此之后:http://www.webtatic.com/packages/httpd-itk/),但它抱怨:

permission denied: mod_wsgi (pid=31322): Unable to connect to WSGI daemon process
'myapp.djangoserver' on '/var/run/wsgi.31085.0.1.sock' after multiple attempts.

解决此问题后(通过授予 777 文件测试权限)我仍然拥有 apache 作为文件的所有者。

我的 conf 文件如下所示:

<VirtualHost *:80>

    ServerName myapp
    ServerAlias myapp 
    DocumentRoot /usr/share/myapp

    <Directory /usr/share/myapp>
        Order allow,deny
        Allow from all
    </Directory>

    WSGIDaemonProcess syntyma.djangoserver processes=10 threads=20 display-name=%{GROUP}
    WSGIProcessGroup myapp.djangoserver

    WSGIScriptAlias / /usr/share/myapp/apache/django.wsgi
    CustomLog logs/myapp-access.log combined
    ErrorLog logs/myapp-error.log

    LogLevel debug
    AssignUserId newuser newuser

</VirtualHost>
WSGISocketPrefix /var/run/wsgi

,以及创建的测试文件:

ls -l /tmp/ggg
-rw-r--r-- 1 apache apache 3 Sep  6 09:46 /tmp/ggg

.

我如何使用 htttpd-itk 或任何其他解决方案(如 suEXEC 或类似解决方案)实现我的目标?

谢谢。

【问题讨论】:

    标签: python django apache apache2 redhat


    【解决方案1】:

    WSGIDaemonProcess 有一个user 参数,用于运行守护进程的用户。在你的情况下:

    WSGIDaemonProcess syntyma.djangoserver user=newuser processes=10 etc...
    

    来自documentation

    用户=名称 |用户=#uid.rst

    定义守护程序处理的用户的 UNIX 用户名或数字用户 uid 应该运行为。如果未提供此选项 守护进程将以与 Apache 相同的用户身份运行 运行子进程并按照用户指令的定义。

    请注意,如果 Apache 未以 root 用户身份启动,则此选项将被忽略,其中 无论设置如何,守护进程都将以启动 Apache 的用户身份运行。

    还要注意 mod_wsgi 不允许您以 root 身份运行守护进程组 用户由于运行的安全风险 以 root 身份访问 Web 应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-17
      • 2019-07-16
      • 2015-06-18
      • 2021-05-28
      • 2020-07-04
      • 2018-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多