I'm serving a Go binary located in /var/www/bin/binary:

location ~ (binary) {
     root /var/www/bin;

However, when I download it with wget http://example.com/binary, I can't run it right away, since it's not an executable anymore. I need to run chmod +x binary first.

How can I fix this? Thanks.

Edit: found a similar question with a larger discussion: https://unix.stackexchange.com/questions/82578/why-is-that-when-i-download-a-binary-from-the-web-it-doesnt-have-executable-per

  • 1
    This sounds like a problem with your web client, not the web server. – Michael Hampton Jan 2 '16 at 23:32

File permissions are not communicated in the process of an HTTP file transfer. All nginx does is open the binary file, read the data, and stream it to the client (wget). Setting permissions on the client machine is determined by the umask on the client, and whatever else your web client browser might do to it.

If you're looking to simplify the steps to download and execute the binary, there are a few approaches you could take. One would simply be:

wget -O binary http://example.com/binary && chmod +x ./binary && ./binary

Or, you could place a shell script at http://example.com/install.sh:


if wget -O "binary" "http://example.com/binary"; then
    chmod +x "./binary"
    echo "Successfully installed binary. To run, use: ./binary"

    # Or just run it here:
    # ./binary
    echo "Failed to download binary." >&2

Then, your installation can be:

wget -O - http://example.com/install.sh | sh


curl -o - http://example.com/install.sh | sh

Note that none of these methods of installation are secure, at all. You need to calculate signatures for the binary (and the shell script) and verify them at download time, and I recommend using HTTPS. But, I'm assuming this is for some type of internal use (in which case, security is still usually important)!

  • Thanks for the explanation. I come from a Windows world where all you need is an exe fie. I thought it was the same in nix, but I guess it makes sense from a security point of view. – Alex Jan 3 '16 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.