Перезапись nginx переходит от рискованных операторов if к try_files. Кто-нибудь может помочь преобразовать? (короткая)

3134
user3125310

Я пытаюсь очистить свои правила перезаписи nginx для моего форума vBulletin, на котором есть некоторые модификации и дополнительное программное обеспечение на том же сайте, что вызывает проблемы. У меня все работает так, как должно, но согласно nginx, если это зло, я обеспокоен и хотел бы вместо этого попытаться преобразовать эти несколько правил в try_files.

В настоящее время есть

  1. Правило для статических изображений и файлов, чтобы они не передавались моду seo (например, .gif, .ico, даже .css)

  2. Правило для подпапки mobiquo, которая также называется плагин tapatalk. Чтобы это работало, мне пришлось исключить весь каталог из переписанных.

  3. Если файл не существует. Я не уверен, насколько это важно, но это кажется хорошей идеей. Может быть, это снизить работу сео мод.

Правила nginx переписывают в явно рискованной форме блока:

это выше / forum / block, потому что я хотел дать ему приоритет, если это сделано неправильно, я хотел бы знать.

 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"; }  location /forum/ {  try_files $uri $uri/ /forum/dbseo.php?$args;  if ($request_uri ~* ^/forum/mobiquo) { break; }  if (-f $request_filename) { expires 30d; break; }  if ($request_filename ~ "\.php$" ) { rewrite ^(/forum/.*)$ /forum/dbseo.php last; }   if (!-e $request_filename) { rewrite ^/forum/(.*)$ /forum/dbseo.php last; }  } 

КОНЕЦ

Где-то в моих поисках я нашел шаблон, который я пытался адаптировать, но так как я не понимаю регулярные выражения, я потерпел неудачу :)

место нахождения / {

 # if you're just using wordpress and don't want extra rewrites # then replace the word @rewrites with /index.php 

try_files $ uri $ uri / /index.php;

}

location @rewrites {

 # Can put some of your own rewrite rules in here # for example rewrite ^/~(.*)/(.*)/? /users/$1/$2 last; # If nothing matches we'll just send it to /index.php 

try_files $ uri $ uri / /forum/dbseo.php?$args;

переписать ^ /index.php last;

переписать ^ (/. php) $ /forum/dbseo.php last;

}

0
Я думаю, что ваша проблема с модом dbseo не сам блок !! Digital site 9 лет назад 0

1 ответ на вопрос

0
Bernard Rosset

Try to cleanse you question, especially the end of it shere you are shouting instead of providing code.

Based on the configuration you provided at the top of you question, I ended up with that:

location /forum/ { index dbseo.php; # You obviously wish to send everything erroneous/inexistent to dbseo.php, any index.php file would suffer the regex location below try_files $uri $uri/ /forum/dbseo.php?$args; # Any inexistent file/directory will be handled over to /forum/dbseo.php location ^~ /forum/dbseo.php { # Avoids matching the regex location below (performance) } location ^~ /forum/mobiquo { # Avoids matching any other rules } location ~* \.php$ { try_files /forum/dbseo.php =404; # Be careful here, try to secure your location since the regex can still be manipulated for arbitrary code execution } } 

Nested locations are a good thing for isolation of potentially conflicting location blocks. Keep in mind that regex locations are evaluated seuqentially, thus to avoid the location blocks order having an impact (which is a mess just like Apache configuration), try to always enclose regex locations in prefix ones to avoid several of them following each other.

You can learn about location modifiers on its documentation page.

Maybe are there more subtelties, but you have all the basic information you need in my example. THe job is yours to understand/improve it to better suit your needs. :o)

Похожие вопросы