![如何在与 Flask WSGI 应用程序相同的服务器上的子域上运行 wordpress?](https://linux22.com/image/682859/%E5%A6%82%E4%BD%95%E5%9C%A8%E4%B8%8E%20Flask%20WSGI%20%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E7%9B%B8%E5%90%8C%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84%E5%AD%90%E5%9F%9F%E4%B8%8A%E8%BF%90%E8%A1%8C%20wordpress%EF%BC%9F.png)
去年,我在 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]