Angularjs mod_wsgi-express重写规则导致CSS/JS文件丢失和浏览器崩溃
我有一个烧瓶/角度应用程序,我正在使用这个命令。Flask、Angular和mod_wsgi-express都是此项目的必备组件Angularjs mod_wsgi-express重写规则导致CSS/JS文件丢失和浏览器崩溃,angularjs,apache,.htaccess,mod-wsgi,wsgi,Angularjs,Apache,.htaccess,Mod Wsgi,Wsgi,我有一个烧瓶/角度应用程序,我正在使用这个命令。Flask、Angular和mod_wsgi-express都是此项目的必备组件 $ mod_wsgi-express start-server run_apache_server.wsgi --rewrite-rules rewrite_psyche_data.conf run\u apache\u server.wsgi看起来像这样(psyche\u data\u master是git repo,而psyche\u data是flask应用程
$ mod_wsgi-express start-server run_apache_server.wsgi --rewrite-rules rewrite_psyche_data.conf
run\u apache\u server.wsgi
看起来像这样(psyche\u data\u master
是git repo,而psyche\u data
是flask应用程序的python模块):
我在这里尝试了一些基于帮助论坛的方法来修复404错误(这些错误是由于使用这个HTML选项时角度路由问题引起的,我必须使用这个选项)
1) 当rewrite\u psyche\u data.conf
如下所示:
Options FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
。。。我的页面看起来像原始HTML,我看到控制台错误说“意外标记:我在烧瓶侧进行了一些挖掘,这样做似乎已经解决了问题:
# routing for basic pages (pass routing onto the Angular app)
@app.route('/')
@app.route('/about')
@app.route('/contact')
@app.route('/studies')
def basic_pages(**kwargs):
return make_response(open('psyche_data/templates/index.html').read())
现在,当我加载名为“/about”的路由时“,等等。URL更改,我可以刷新它,并且没有404错误。即使没有重写规则 如果将静态文件放在mod_wsgi-express用于静态文件的目录中,则不需要重写规则,因为默认情况下,mod_wsgi-express生成的配置中包含这些重写规则。如果某个目录中已经有静态文件,您可以使用
--document root
选项来简单地指定它们的位置。我认为--document root
由于我使用了指向项目根的sys.path.insert
而变得毫无用处--document root
与Python代码无关。它是包含静态文件的目录。默认情况下,mod\u wsgi-express
已经使用了您提到的初始重写规则。规则的作用是,如果URL与目录中的静态文件相匹配(由--document root
指定),则将提供静态文件。如果URL与静态文件不匹配,则请求将传递给Python WSGI应用程序进行处理。因此,如果您没有将静态文件放入目录中,以便mod_WSGI-express
进行处理,从一开始就不需要这些重写规则,您的问题都与您的Flask应用程序路由有关。
$ mod_wsgi-express start-server run_apache_server.wsgi --rewrite-rules rewri_psyche_data.conf
Server URL : http://localhost:8000/
Server Root : /tmp/mod_wsgi-localhost:8000:503
Server Conf : /tmp/mod_wsgi-localhost:8000:503/httpd.conf
Error Log File : /tmp/mod_wsgi-localhost:8000:503/error_log (warn)
Rewrite Rules : /Users/Jakob/Desktop/dev_projects/psyche_data_master/rewrite_psyche_data.conf
Request Capacity : 5 (1 process * 5 threads)
Request Timeout : 60 (seconds)
Startup Timeout : 15 (seconds)
Queue Backlog : 100 (connections)
Queue Timeout : 45 (seconds)
Server Capacity : 20 (event/worker), 20 (prefork)
Server Backlog : 500 (connections)
Locale Setting : en_US.UTF-8
[Mon May 22 21:17:00.788635 2017] [mpm_event:notice] [pid 12005:tid 140735965213632] AH00489: Apache/2.4.23 (Unix) mod_wsgi/4.5.15 Python/2.7 configured -- resuming normal operations
[Mon May 22 21:17:00.789013 2017] [core:notice] [pid 12005:tid 140735965213632] AH00094: Command line: 'httpd (mod_wsgi-express) -f /tmp/mod_wsgi-localhost:8000:503/httpd.conf -D MOD_WSGI_MPM_ENABLE_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_WORKER_MODULE -D MOD_WSGI_MPM_EXISTS_PREFORK_MODULE -D FOREGROUND'
$ mod_wsgi-express start-server run_apache_server.wsgi
# routing for basic pages (pass routing onto the Angular app)
@app.route('/')
@app.route('/about')
@app.route('/contact')
@app.route('/studies')
def basic_pages(**kwargs):
return make_response(open('psyche_data/templates/index.html').read())