[SOLVED] Chef server nginx public file serving

I was looking at an old chef recipe that was built on the assumption that you could retrieve content/binaries from public html file on apache under port 80 in a virtual path.

I did a little looking around at nginx.conf and it seems that the default nginx.conf has no public path to serve content from anymore.

I read some documentation about how to create a public location in nginx, but I was struggling to make it work.

I’m thinking SCP might be a better idea anyway, since nodes are in the same private subnet, but was curious how to modify nginx.conf and restart/reload nginx in a way that would open up some other mount point to public download.

Is serving content (large binaries) from public html location a bad idea?

Given the rest of the nginx configuration for chef manage, can someone share a snippet of an nginx conf they use for sharing content publically that works? I tried to create a new server in the nginx.conf on a different port pointing to a server mounted file location, but couldn’t make it work.

I’m not sure how good of an idea it is to serve files directly from the chef server if you have other alternatives such as putting the files on S3, but you could achieve it by doing something like the following:

Create a file /var/opt/opscode/nginx/etc/addon.d/70-public-files_external.conf with something like:

location ~ ^/files/ {
    root /some/path;
}

and run chef-server-ctl restart nginx to restart nginx. Then, place your files in /some/path/files/ and you should be able to get at your files by going to https://your_chef_server/files/filename. This is similar to the method used by manage to serve static assets (see the 30-chef-manage_external.conf in the same directory to see how it does things).

would I have to reference this external file in an include in nginx.conf?
I see these in nginx.conf:

Include upstream definitions for addons include /var/opt/opscode/nginx/etc/addon.d/_upstreams.conf; # Include internal routes for addons include /var/opt/opscode/nginx/etc/addon.d/_internal.conf;

but nothing for external.conf

one other silly question... is the path specified in root, relative to the document root of nginx or relative to / on server?

Mark_Harrison Chef Software Staff
December 7 |

I’m not sure how good of an idea it is to serve files directly from the chef server if you have other alternatives such as putting the files on S3, but you could achieve it by doing something like the following:

Create a file /var/opt/opscode/nginx/etc/addon.d/70-public-files_external.conf with something like:
location ~ ^/files/ {
root /some/path;
}

and run chef-server-ctl restart nginx to restart nginx. Then, place your files in /some/path/files/ and you should be able to get at your files by going to https://your_chef_server/files/filename. This is similar to the method used by manage to serve static assets (see the 30-chef-manage_external.conf in the same directory to see how it does things).

Visit Topic or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, click here.

I see the external addons are referenced via the chef_https_lb.conf file.So that answers that part of my question.

Mark_Harrison Chef Software Staff
December 7 |

I’m not sure how good of an idea it is to serve files directly from the chef server if you have other alternatives such as putting the files on S3, but you could achieve it by doing something like the following:

Create a file /var/opt/opscode/nginx/etc/addon.d/70-public-files_external.conf with something like:
location ~ ^/files/ {
root /some/path;
}

and run chef-server-ctl restart nginx to restart nginx. Then, place your files in /some/path/files/ and you should be able to get at your files by going to https://your_chef_server/files/filename. This is similar to the method used by manage to serve static assets (see the 30-chef-manage_external.conf in the same directory to see how it does things).

Visit Topic or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, click here.

I haven’t tested it to be certain, but I think it’s relative to / on the server, so your files would have to be inside a files/ directory in addition to the path you specify in the config file. There may be something you can do to rewrite the URL to strip off /files from the beginning, perhaps try something like rewrite ^/files/(.*) /$1 inside the location directive.

Thanks! I figured it out. Unfortunately all my testing was failing because I was using the file name: "index.html" for my simple html file.
there must be another directive that overrides that, because I'd always get 404 on index.html, but as soon as I used test.html instead of index.html, all my path/locations worked!

Mark_Harrison Chef Software Staff
December 7 |

I haven’t tested it to be certain, but I think it’s relative to / on the server, so your files would have to be inside a files/ directory in addition to the path you specify in the config file. There may be something you can do to rewrite the URL to strip off /files from the beginning, perhaps try something like rewrite ^/files/(.*) /$1 inside the location directive.

Visit Topic or reply to this email to respond.

In Reply To

jobmiller
December 7 |

would I have to reference this external file in an include in nginx.conf? I see these in nginx.conf: Include upstream definitions for addons include /var/opt/opscode/nginx/etc/addon.d/_upstreams.conf; # Include internal routes for addons include /var/opt/opscode/nginx/etc/addon.d/_internal.…
Visit Topic or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, click here.