H
H
Horosh2942021-03-31 17:19:07
Nginx
Horosh294, 2021-03-31 17:19:07

Set up location in nginx in centos 7?

I'm moving from apache to nginx. Website on DLE. htaccess rules rewritten in PHP.
However, one rule cannot be expressed using PHP. This is the rule that redirects all requests to index.php .
To do this, you need to change the nginx config file. To do this, I go to the /etc/nginx/vhosts/www-root/site.ru.conf file.
Its content:

server {
  server_name site.ru www.site.ru;
  charset off;
  index index.php index.html;
  disable_symlinks if_not_owner from=$root_path;
  include /etc/nginx/vhosts-includes/*.conf;
  include /etc/nginx/vhosts-resources/site.ru/*.conf;
  access_log /var/www/httpd-logs/site.ru.access.log;
  error_log /var/www/httpd-logs/site.ru.error.log notice;
  ssi on;
  return 301 https://$host:443$request_uri;
  set $root_path /var/www/www-root/data/www/site.ru;
  root $root_path;
  location / {
    location ~ [^/]\.ph(p\d*|tml)$ {
      try_files /does_not_exists @php;
    }
  }
  listen 111.111.11.11:80;
  location @php {
    fastcgi_index index.php;
    fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]";
    fastcgi_pass unix:/var/www/php-fpm/www-root.sock;
    fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
    try_files $uri =404;
    include fastcgi_params;
  }
}
server {
  server_name site.ru www.site.ru;
  ssl_certificate "/var/www/httpd-cert/www-root/site.ru.crt";
  ssl_certificate_key "/var/www/httpd-cert/www-root/site.ru.key";
  ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
  ssl_prefer_server_ciphers on;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_dhparam /etc/ssl/certs/dhparam4096.pem;
  charset off;
  index index.php index.html;
  disable_symlinks if_not_owner from=$root_path;
  include /etc/nginx/vhosts-includes/*.conf;
  include /etc/nginx/vhosts-resources/site.ru/*.conf;
  access_log /var/www/httpd-logs/site.ru.access.log;
  error_log /var/www/httpd-logs/site.ru.error.log notice;
  ssi on;
  set $root_path /var/www/www-root/data/www/site.ru;
  root $root_path;
  location / {
    location ~ [^/]\.ph(p\d*|tml)$ {
      try_files /does_not_exists @php;
    }
  }
  listen 111.111.11.11:443 ssl http2;
  location @php {
    fastcgi_index index.php;
    fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]";
    fastcgi_pass unix:/var/www/php-fpm/www-root.sock;
    fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
    try_files $uri =404;
    include fastcgi_params;
  }
}

What should be added and where? I haven't been able to figure it out myself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-03-31
@Horosh294

location / {
    location ~ [^/]\.ph(p\d*|tml)$ {
        try_files /does_not_exists @php;
    }
}
listen 111.111.11.11:443 ssl http2;
location @php {

Replaced by
location / {
        try_files $uri $uri/ /index.php;
}
listen 111.111.11.11:443 ssl http2;
location ~ \.php$ {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question