R
R
Razhapov Mansur2016-05-09 20:25:33
Nginx
Razhapov Mansur, 2016-05-09 20:25:33

DLE 11 + nginx does not work Rewrite, what to do?

site 2city.uz (through 2city.uz/index.php it works, but if you just write, there is no rewrite)

server {
  listen 80;
  server_name 2city.uz;
  root /var/www/2city.uz;
  set $root_path /var/www/2city.uz;

  access_log off;
  error_log /var/log/nginx/error-2city.log;

  # Редиректы
  rewrite "^/page/([0-9]+)(/?)$" /index.php?cstart=$1 last;

  # Сам пост
  rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page,([0-9]+),([0-9]+),(.*).html(/?)+$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&cstart=$5&news_name=$6&seourl=$6 last;
  rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page,([0-9]+),(.*).html(/?)+$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&news_name=$5&seourl=$5 last;
  rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/print:page,([0-9]+),(.*).html(/?)+$" /engine/print.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&news_name=$5&seourl=$5 last;
  rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*).html(/?)+$" /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_name=$4&seourl=$4 last;

  rewrite "^/([^.]+)/page,([0-9]+),([0-9]+),([0-9]+)-(.*).html(/?)+$" /index.php?newsid=$4&news_page=$2&cstart=$3&seourl=$5&seocat=$1 last;
  rewrite "^/([^.]+)/page,([0-9]+),([0-9]+)-(.*).html(/?)+$" /index.php?newsid=$3&news_page=$2&seourl=$4&seocat=$1 last;
  rewrite "^/([^.]+)/print:page,([0-9]+),([0-9]+)-(.*).html(/?)+$" /engine/print.php?news_page=$2&newsid=$3&seourl=$4&seocat=$1 last;
  rewrite "^/([^.]+)/([0-9]+)-(.*).html(/?)+$" /index.php?newsid=$2&seourl=$3&seocat=$1 last;

  rewrite "^/page,([0-9]+),([0-9]+),([0-9]+)-(.*).html(/?)+$" /index.php?newsid=$3&news_page=$1&cstart=$2&seourl=$4 last;
  rewrite "^/page,([0-9]+),([0-9]+)-(.*).html(/?)+$" /index.php?newsid=$2&news_page=$1&seourl=$3 last;
  rewrite "^/print:page,([0-9]+),([0-9]+)-(.*).html(/?)+$" /engine/print.php?news_page=$1&newsid=$2&seourl=$3 last;
  rewrite "^/([0-9]+)-(.*).html(/?)+$" /index.php?newsid=$1&seourl=$2 last;

  # За день
  rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})(/?)+$" /index.php?year=$1&month=$2&day=$3 last;
  rewrite "^/([0-9]{4})/([0-9]{2})/([0-9]{2})/page/([0-9]+)(/?)+$" /index.php?year=$1&month=$2&day=$3&cstart=$4 last;

  # За весь месяц
  rewrite "^/([0-9]{4})/([0-9]{2})(/?)+$" /index.php?year=$1&month=$2 last;
  rewrite "^/([0-9]{4})/([0-9]{2})/page/([0-9]+)(/?)+$" /index.php?year=$1&month=$2&cstart=$3 last;

  # Вывод за весь год
  rewrite "^/([0-9]{4})(/?)+$" /index.php?year=$1 last;
  rewrite "^/([0-9]{4})/page/([0-9]+)(/?)+$" /index.php?year=$1&cstart=$2 last;

  # вывод отдельному тегу
  rewrite "^/tags/([^/]*)(/?)+$" /index.php?do=tags&tag=$1 last;
  rewrite "^/tags/([^/]*)/page/([0-9]+)(/?)+$" /index.php?do=tags&tag=$1&cstart=$2 last;

  # поиск по доп полям
  rewrite "^/xfsearch/([^.]*)(/?)+$" /index.php?do=xfsearch&xf=$1 last;
  rewrite "^/xfsearch/([^.]*)/page/([0-9]+)(/?)+$" /index.php?do=xfsearch&xf=$1&cstart=$2 last;

  # вывод для отдельного юзера
  rewrite "^/user/([^/]*)/rss.xml$" /engine/rss.php?subaction=allnews&user=$1 last;
  rewrite "^/user/([^/]*)(/?)+$" /index.php?subaction=userinfo&user=$1 last;
  rewrite "^/user/([^/]*)/page/([0-9]+)(/?)+$" /index.php?subaction=userinfo&user=$1&cstart=$2 last;
  rewrite "^/user/([^/]*)/news(/?)+$" /index.php?subaction=allnews&user=$1 last;
  rewrite "^/user/([^/]*)/news/page/([0-9]+)(/?)+$" /index.php?subaction=allnews&user=$1&cstart=$2 last;
  rewrite "^/user/([^/]*)/news/rss.xml(/?)+$" /engine/rss.php?subaction=allnews&user=$1 last;

  # вывод всех последних новостей
  rewrite "^/lastnews(/?)+$" /index.php?do=lastnews last;
  rewrite "^/lastnews/page/([0-9]+)(/?)+$" /index.php?do=lastnews&cstart=$1 last;

  # вывод в виде каталога
  rewrite "^/catalog/([^/]*)/rss.xml$" /engine/rss.php?catalog=$1 last;
  rewrite "^/catalog/([^/]*)(/?)+$" /index.php?catalog=$1 last;
  rewrite "^/catalog/([^/]*)/page/([0-9]+)(/?)+$" /index.php?catalog=$1&cstart=$2 last;

  # вывод непрочитанных статей
  rewrite "^/newposts(/?)+$" /index.php?subaction=newposts last;
  rewrite "^/newposts/page/([0-9]+)(/?)+$" /index.php?subaction=newposts&cstart=$1 last;

  # вывод избранных статей
  rewrite "^/favorites(/?)+$" /index.php?do=favorites last;
  rewrite "^/favorites/page/([0-9]+)(/?)+$" /index.php?do=favorites&cstart=$1 last;

  rewrite "^/rules.html$" /index.php?do=rules last;
  rewrite "^/statistics.html$" /index.php?do=stats last;
  rewrite "^/addnews.html$" /index.php?do=addnews last;
  rewrite "^/rss.xml$" /engine/rss.php last;
  rewrite "^/sitemap.xml$" /uploads/sitemap.xml last;

  if (!-d $request_filename) {
        rewrite "^/([^.]+)/page/([0-9]+)(/?)+$" /index.php?do=cat&category=$1&cstart=$2 last;
        rewrite "^/([^.]+)/?$" /index.php?do=cat&category=$1 last;
  }

  if (!-f $request_filename) {
        rewrite "^/([^.]+)/rss.xml$" /engine/rss.php?do=cat&category=$1 last;
        rewrite "^/page,([0-9]+),([^/]+).html$" /index.php?do=static&page=$2&news_page=$1 last;
        rewrite "^/print:([^/]+).html$" /engine/print.php?do=static&page=$1 last;
  }

  if (!-f $request_filename) {
        rewrite "^/([^/]+).html$" /index.php?do=static&page=$1 last;
  }

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/var/run/php5-2city.sock;
  }

}

and here are the settings of the nginx config itself
user  www-data;
worker_processes  4;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alegzz, 2016-05-09
@alegzz

nginx.org/ru/docs/http/ngx_http_index_module.html#index

M
metajiji, 2016-05-13
@metajiji

...
index index.php index.html index.htm;
location ~ \.php$ {
...
fastcgi_index  index.php;
}

Judging by the config, index is not specified - the default document. In the case of using nginx + php-fpm, you need to specify it in 2 places, as in the code above.
By the way, the config is too complicated and terrible, I'm sure that it can be done without this bunch of rewrites, as well as without if constructs. I recommend reading about try_files and looking for ready-made nginx configs for DLE, I'm sure they exist in a more pleasant form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question