Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server static files from FTP server using NGINX

Tags:

nginx

ftp

I have a local network, on which there are some old insecure services. I use nginx reverse proxy with client certificates authentication as safe entrypoint to this local network from the Internet. Till now I used it only to proxy HTTP servers using

    location / {
        proxy_pass http://192.168.123.45:80/;
    }

and everything works fine.

But now I would like to serve static files, that are accessible through FTP on a local server, I tried simply:

    location /foo {
        proxy_pass ftp://user:[email protected]:5000/;
    }

but that doesn't work, and I could not find anything that would simply proxy HTTP request to FTP request.

Is there any way to do this?

like image 911
michalhosna Avatar asked Mar 05 '23 07:03

michalhosna


1 Answers

Nginx doesn't support proxying to FTP servers. At best, you can proxy the socket... and this is a real hassle with regular old FTP due to it opening new connections on random ports every time a file is requested.

What you can probably do instead is create a FUSE mount to that FTP server on some local path, and serve that path with Nginx like normal. To that end, CurlFtpFS is one tool for this. Tutorial: https://linuxconfig.org/mount-remote-ftp-directory-host-locally-into-linux-filesystem

(Note: For security and reliability, it's strongly recommended you migrate away from FTP when possible. Consider SSH/SFTP instead.)

like image 95
Brad Avatar answered Apr 10 '23 12:04

Brad