Пытаюсь настроить перенаправления для Codeigniter так, чтобы работал URL вида localhost/codeigniter/class
, так localhost/codeigniter/class
. URL подобного вида используются также в Drupal 8, поэтому решил сделать перенаправление по регэкспу:
location ~ /(drupal|codeigniter)/ {
try_files $uri $uri/ @rewrite8;
}
location @rewrite8 {
rewrite ^/(drupal|codeigniter) /$1/index.php;
}
Однако при переходе на страницу мне предлагают скачать файл (в заголовке ответа MIME-тип выглядит как octet-stream
).
Если не использовать регэкспов:
location /codeigniter/ {
try_files $uri $uri/ @rewrite8;
}
то всё работает нормально и отдаётся text/html
.
С чем это может быть связано и как мне сделать правильное перенаправление?
UPD. Полный конфиг:
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location /codeigniter/ {
try_files $uri $uri/ @rewrite8;
}
location /drupal7/ {
try_files $uri $uri/ @rewrite7;
}
location @rewrite7 {
rewrite ^/drupal7/(.*)$ /drupal7/index.php?q=$1;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
}
location @rewrite8 {
rewrite ^/(drupal|codeigniter) /$1/index.php;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}