D
D
dura2282019-07-09 23:23:57
Nginx
dura228, 2019-07-09 23:23:57

How to set up Nginx redirects in Heroku?

The root of the project contains index.php and nginx_app.conf.
Content of nginx_app.conf:

location / {
                try_files $uri $uri/ =404;
                rewrite ^(.+)$ /index.php?key=$1;
        }

I run the command in the console
vendor/bin/heroku-php-nginx -C nginx_app.conf

As a result, output
Using Nginx server-level configuration include 'nginx_app.conf'
Optimizing defaults for 1X dyno...
4 processes at 128MB memory limit.
Starting php-fpm...
Starting nginx...

Going to my site https://mysite.herokuapp.com/jhkjh shows 404 not found when it should return index.php.
On localhost, with these settings, everything works correctly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pugovkin, 2019-07-15
@Driver86

location ~/(.*)$ {
    try_files $uri $uri/ /index.php?key=$1;
}

Or like this:
location / {
    try_files $uri $uri/ /index.php?key=$uri;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question