Apache:重定向到 WSGI 脚本是错误的?

Apache: redirect to WSGI script is wrong?

我将 Flask 应用程序部署到 Apache。这可行,但我添加了一些内容以将非 www 流量重定向到 www 域。

<VirtualHost *:80>
    ServerName myapp.com
    WSGIDaemonProcess myapp python-home=/home/ubuntu/envs/myapp user=ubuntu group=ubuntu threads=5
    WSGIScriptAlias / /home/ubuntu/apps/myapp/myapp.wsgi
    Alias /static /home/ubuntu/apps/myapp/myapp/static
    <Directory /home/ubuntu/apps/myapp>
        WSGIProcessGroup myapp
        WSGIApplicationGroup %{GLOBAL}
        Require all granted
        AllowOverride All
        RewriteEngine On
        RewriteBase /
        RewriteCond %{HTTP_HOST} !^www\. [NC]
        RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/ [R=301,L]
    </Directory>
</VirtualHost>

这有效!但是,当我浏览 myapp.com/test.html 时,我被重定向到 www.myapp.com/myapp。 wsgi/test.html - 这是不正确的!我尝试修改上面文件中的一些参数,但目前没有得到想要的结果。

关于如何解决这个问题的任何提示?

亲切的问候, B.

我设法使用以下配置进行工作:

<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    ServerName myapp.com
    WSGIDaemonProcess myapp python-home=/home/ubuntu/envs/myapp user=ubuntu group=ubuntu threads=5
    WSGIScriptAlias / /home/ubuntu/apps/myapp/myapp.wsgi
    Alias /static /home/ubuntu/apps/myapp/myapp/static
    <Directory /home/ubuntu/apps/myapp>
        WSGIProcessGroup myapp
        WSGIApplicationGroup %{GLOBAL}
        Require all granted
    </Directory>
</VirtualHost>