我正在从mod_php迁移到nginx。 我得到了一切工作,除了这个重写..我只是不熟悉的nginxconfiguration知道正确的方法来做到这一点。
通过在nginx网站上查看示例,我想到了这一点。
server { server_name test01.www.myhost.com; root /home/vhosts/my_home/blah; access_log /var/log/nginx/blah.access.log; error_log /var/log/nginx/blah.error.log; index index.php; location / { try_files $uri $uri/ @rewrites; } location @rewrites { rewrite ^ /index.php last; rewrite ^/ht/userGreeting.php /js/iFrame/index.php last; rewrite ^/ht/(.*)$ /$1 last; rewrite ^/userGreeting.php$ /js/iFrame/index.php last; rewrite ^/a$ /adminLogin.php last; rewrite ^/boom\/(.*)$ /boom/index.php?q=$1 last; rewrite ^favicon.ico$ favico_ry.ico last; } # This block will catch static file requests, such as images, css, js # The ?: prefix is a 'non-capturing' mark, meaning we do not require # the pattern to be captured into $1 which should help improve performance location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { # Some basic cache-control for static files to be sent to the browser expires max; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; } include php.conf; }
我遇到的问题是这个重写:
rewrite ^ht\/(.*)$ /$1 last;
这个重写的请求中有99%是静态文件。 所以我想也许它被发送到静态文件部分,这就是事情被搞砸了?
我试图添加这个,但它没有工作:
location ~* ^ht\/.*\.(?:ico|css|js|gif|jpe?g|png)$ { # Some basic cache-control for static files to be sent to the browser expires max; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; }
任何帮助,将不胜感激。 我知道最好的办法是将代码中/ht/whatever.jpg的引用更改为/whatever.jpg,但是现在不是这样。
试试这个: location ~ ((ht/.*)|(?:ico|css|js|gif|jpe?g|png)$)
我通过添加来解决这个问题
try_files $uri $uri/ @rewrites;
到静态文件位置块。