我正在努力
/ -> /foo/index.html /(about|people|contact) -> /foo/(about|people|contact).html /blah.(jpg|css|js) -> /foo/blah.(jpg|css|js)
但也
/index.html -> 404 /(about|people|contact).html -> 404 * -> 404
到目前为止我有:
# Serve our home page. location / { root /foo/; } location = / { alias /foo/; } location ~ /(about|people|contact) { default_type text/html; alias /foo/$1.html; } location ~ /(.+\.(jpg|css|js)) { root /foo/; }
虽然这暴露了我想通过非.htmlurl公开的文件,它不会404任何文件。
在此先感谢您的帮助。
问题是,我曾经尝试过的第一件事(在我的问题中没有提到),
location = / { alias /foo/index.html; }
结果是
"/var/www/intro/index.htmlindex.html" is not a directory
在我上面的问题中,我改变了这个东西,至less可以为页面服务,再加上一条无用的线,expression了我的意图:
location / { root /foo/; } location = / { alias /foo/; } # seems to be ignored
从http://ngxbot.lustfield.net/logs/%23nginx/2012/01/%23nginx.19.log我发现你可以replace第二行:
location = / { root /foo/; rewrite ^ /index.html break; }
然后让location /点在其他地方,例如一个空目录:
location / { root /var/www/; }
不知道这是最优雅的解决scheme,但它似乎工作。