0

I have a php application(Yii framework) that lives on Heroku. I am trying to get the nginx configuration set up properly so that the app serves correctly. Right now, it serves the PHP but not that static files. Below is my nginx configuration along with the command inside the Procfile. Any help is appreciated.

--Procfile--
web: vendor/bin/heroku-php-nginx -C nginx.conf

--nginx.conf--
location / {
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    rewrite ^(.*)$ /myapp/public/index.php/$1 last;
}

location /css {
    alias /myapp/public/css/;
}

location /js {
    alias /myapp/public/js/;
}

location /img {
    alias /myapp/public/img/;
}

location ~ \.php$ {
    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_pass  heroku-fcgi;
}
3
  • Can you provide an example of a static file that isn't being served? Like example.com/assets/js/jquery.min.js... Commented Jul 10, 2014 at 21:28
  • 1
    FYI, docs for the try_files directive in nginx (link) Commented Jul 10, 2014 at 21:29
  • @ALtheX thanks for the information, I was able to finally figure it out from Google ;D Commented Jul 10, 2014 at 22:08

1 Answer 1

2

I ended up getting everything working with this config below:

location / {
    root /app/myapp/public;

    try_files $uri @rewriteapp;
}

location @rewriteapp {
    rewrite ^(.*)$ /myapp/public/index.php/$1 last;
}
Sign up to request clarification or add additional context in comments.

3 Comments

You don't need the last section; that's in the outer default config already.
Also, you shouldn't define the document root like this. Use the following: location / { try_files $uri @rewriteapp; } location @rewriteapp { rewrite ^(.*)$ index.php/$1 last; } And in your Procfile, use web: vendor/bin/heroku-php-nginx -C nginx.conf myapp/public/ (see devcenter.heroku.com/articles/…)
@dzuelke, I had tried many things but I'm still having a problem. Do you have something to accrescent here stackoverflow.com/questions/29418400/…?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.