0

Here's my conf for the website on Rails 3.1:

server {
    listen 80;
    server_name test.mysite.com www.test.mysite.com;
    root /var/www/mysite/test/current/public;

    location ~* ^/assets/ {
            expires max;
            add_header Cache-Control public;
            break;
    }

    passenger_enabled on;


    error_page  404  /404.html;
    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /500.html;

    client_max_body_size 10M;

    if (-f $document_root/maintenance.html) {
            rewrite  ^(.*)$  /maintenance.html break;
    }

}

Only images are rendered though. css and js show 404 page. What am I doing wrong?

2
  • Are you sure you have set the correct permissions on your CSS, JavaScript files ? Commented Jul 17, 2011 at 22:21
  • Yes, I checked it, READ for everyone. Commented Jul 18, 2011 at 1:27

3 Answers 3

1

I'd like to share with you my configuration on Github of nginx+passenger in production mode. it resolves you problem with server static content right way

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks. Good stuff in there. However, I looked through it carefully and I haven't found what is the problem with my configuration. The only relevant block about static assets is basically the same as mine. To be sure I copypasted it, but still no luck. What am I not seeing?
where your css/js are located? can you copy-paste nginx error.log please?
and check the permissions for the directories, to ensure that nginx can serve them as well. Rails3 turned off the assets serve by default, so nginx probably has some issues with access to static content
css/js are in /var/www/mysite/test/current/public/assets error.log contains nothing related to the problem. The last entry is unknown directive "gzip_static" in /etc/nginx/sites-enabled/test.mysite.com:8 (don't know why it's not supported, but I removed it anyway). I visited the page, then checked error.log - nothing new appeared in it. Permissions are set to "READ for all" on files and "EXECUTE for all" on dirs.
if "gzip_static" is in the configs, it's looking gzipped files only.
|
1

Apparently, I haven't payed enough attention. Those css and js files were not actually compiled for some reason and, thus, have not appeared in assets/public dir. At least not all of them: for instance application.css is there, but other css files are not. Anyway, that is not an nginx problem, so I'm marking this as the right answer.

Comments

0

I had the same issue, one of my stylesheets was not being compiled, but this guide provided me with a solution.

I added my custom.css to config/environments/production.rb this way...

config.assets.precompile += ['custom.css']

After that I issued bundle exec rake assets:precompile and my problem was solved.

Comments

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.