去年,我在 Apache 主机上运行了一个 Flask/WSGI 应用程序,运行良好。httpd.conf 设置如下:
ServerName myapp.com
WSGISocketPrefix /var/run/wsgi
WSGIScriptAlias / /var/www/myapp/myapp/myapp.wsgi
WSGIDaemonProcess myapp user=user group=user threads=5
<Directory /var/www/myapp/myapp>
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^/?(.*)$ https://www.myapp.com/$1 [R=301,L]
所以你去https://myapp.com或者https://myapp.com/blah并且运行良好。
我的客户现在想为网站建立一个 Wordpress 博客,地址是 blog.myapp.com。我的 Apache 很弱,所以我不确定如何正确地做到这一点。以下是我在 httpd.conf 中尝试的操作:
WSGISocketPrefix /var/run/wsgi
NameVirtualHost *:80
<VirtualHost *:80>
ServerName myapp.com
WSGIScriptAlias / /var/www/myapp/myapp/myapp.wsgi
WSGIDaemonProcess myapp user=user group=user threads=5
<Directory /var/www/myapp/myapp>
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^/?(.*)$ https://www.myapp.com/$1 [R=301,L]
</VirtualHost>
<VirtualHost *:80>
ServerName blog.myapp.com
DocumentRoot "/var/www/html/wordpress"
</VirtualHost>
HTTPD 服务重新启动没有问题,但是当我转到http://myapp.com我得到了 Apache 测试页面。我可以按照我的客户的要求做吗?
答案1
我成功说服我的客户将博客的位置更改为:
myapp.com/blog
这使得解决方案变得更加简单,只需要添加一行别名指令:
ServerName myapp.com
Alias /blog /var/www/html/wordpress
WSGISocketPrefix /var/run/wsgi
WSGIScriptAlias / /var/www/myapp/myapp/myapp.wsgi
WSGIDaemonProcess myapp user=user group=user threads=5
<Directory /var/www/myapp/myapp>
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^/?(.*)$ https://www.myapp.com/$1 [R=301,L]