views:

38

answers:

1

Here is my config:

user nobody nobody;
worker_processes  2;

error_log  /rails/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15;
    passenger_ruby /usr/local/bin/ruby;
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" -- "$cookie_YBY" ';
    access_log  /rails/nginx_access.log  main;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    client_header_timeout       10m;
    client_body_timeout         10m;
    send_timeout                10m;
    connection_pool_size        256;
    client_header_buffer_size   1k;
    # large headers needed for FF
    large_client_header_buffers 4 8k;
    request_pool_size           4k;

    gzip on;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_min_length 1100;
    gzip_buffers    4 8k;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    output_buffers  1 32k;
    postpone_output 1460;
    server {
        listen 80;
        server_name optisol.s0hoo.com;
        client_max_body_size 50M;
        #access_log /rails/access.log;
        error_log /rails/smart_error.log;
        root /rails/smart_ads_archive/public;
        passenger_enabled on;
        location ~* \.(ico|css|js|gif|jp?g|png)(\?[0-9]+)?$ {
            expires max;
            access_log off;
            break;
        }
    }

}

and im running on the latest nginx, ruby on rails 2.3.5, and the latest passenger. The problem I am having is that I want to deploy to a sub_uri, so i modify the server config to have:

root /websites/rails;
passenger_base_uri /smart_ads_archive;    # <--- been added.

but when I visit the page all of the css that links to /images/etc/etc/ are coming up with 404 because the rails app is sitting in the sub uri. On my shared host w/ Apache I am able to deploy rails app to sub directories in public_html without a problem and with no configuration to my rails app and with css files pointing to /images... and it just looks at the rails public/images folder.

The question: is there a setting I am missing in Rails or in Nginx? Or do I need to go find all of the /images/ references and /css/ and /js/ and manually prepend /smart_ads_archive/js.. etc.

Thanks for the help!

A: 

Please read the documentation for how to use a Sub URI in Nginx/Passenger.

Short version: you need a symlink in your root to the Rails /public/ folder. Passenger_base_uri takes the name of that symlink as its parameter.

Patrick McKenzie
Hi Patrick. I did follow the instructions there. I have a symlink in my root dir pointing to the public folder of my rails app. The issue I am having, and maybe I was not clear enough, is that the css files and js files that refer to the path "/images/file.png" are trying to hit the tld/images/file.png and not the tld/sub_uri/images/file.png. Directories generated by rails seem to get the sub_uri just fine, it's the explicit mentioning of resources that come up with not found.
Mike