Setting Up a File Server on VPS with Nginx
This guide provides a detailed walkthrough to set up a web file server using Nginx, h5ai, Aria2, and AriaNG on a Debian-based VPS. Additionally, it explains how to enhance functionality with SSL and local development options.
Background
Learn to host a file server with h5ai, manage downloads using Aria2, and set up configurations via Nginx on a Debian 9 VPS.
How to
1. Basic Nginx Configuration
Update the Nginx configuration to host your file server:
- Open
/etc/nginx/sites-enabled/default
and add:server { listen xxxx; # Replace xxxx with your desired port server_name localhost; root /home/bh/share; location / { autoindex on; # Enable directory listing autoindex_exact_size on; # Show file sizes autoindex_localtime on; # Show local time for files } }
- Reload Nginx:
sudo service nginx reload
- Access the file server at
yourdomain.com:xxxx
.
2. Enhance with h5ai
Install h5ai
- Install PHP:
sudo apt install php
- Update the Nginx configuration in
/etc/nginx/sites-enabled/default
:server { listen xxxx; server_name localhost; root /home/bh/share; index index.html /_h5ai/public/index.php; location ~ \.php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; # Check your PHP socket path include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } }
- Reload Nginx:
sudo service nginx reload
3. Add Folder Password Protection
Protect specific folders with HTTP authentication:
- Install
apache2-utils
:sudo apt install apache2-utils
- Create a password file and user:
htpasswd -c /etc/nginx/passwd your-username
- Update Nginx configuration:
location /private { autoindex on; auth_basic "Restricted Access"; auth_basic_user_file /etc/nginx/passwd; }
- Reload Nginx:
sudo service nginx reload
4. Integrate Aria2 and AriaNG
Install Aria2
sudo apt install aria2
Configure Aria2
- Create configuration files:
mkdir ~/.aria2 vim ~/.aria2/aria2.conf
- Add the following:
dir=/home/your-username/aria2/download enable-rpc=true rpc-listen-all=true rpc-listen-port=6800 rpc-secret=your_rpc_password file-allocation=none continue=true max-concurrent-downloads=10
- Run Aria2:
aria2c --conf-path="/home/your-username/.aria2/aria2.conf"
Install and Configure AriaNG
- Download AriaNG.
- Place files in
/home/your-username/aria2/AriaNG
.
Configure Nginx for Aria2
- Create a new Nginx configuration in
/etc/nginx/sites-available/aria.conf
:server { listen 443 ssl; server_name your-domain.com; root /home/your-username/aria2/AriaNG; location ^~ /jsonrpc { proxy_pass http://127.0.0.1:6800/jsonrpc; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } ssl_certificate /path/to/fullchain.pem; # Adjust paths ssl_certificate_key /path/to/privkey.pem; }
- Enable the configuration:
sudo ln -s /etc/nginx/sites-available/aria.conf /etc/nginx/sites-enabled/ sudo service nginx reload
- Visit the web interface and configure RPC settings in AriaNG.
5. Set Up SSL with Certbot
- Install Certbot:
sudo apt install certbot
- Obtain and configure an SSL certificate:
sudo certbot --nginx
- Update Nginx configurations to use SSL.
6. Run Aria2 as a Daemon
- Create a systemd service:
sudo vim /etc/systemd/system/aria2.service
- Add:
[Unit] Description=Aria2c download manager After=network.target [Service] User=your-username ExecStart=/usr/bin/aria2c --conf-path=/home/your-username/.aria2/aria2.conf Restart=on-failure [Install] WantedBy=multi-user.target
- Enable and start the service:
sudo systemctl enable aria2.service sudo systemctl start aria2.service
7. Local Development Options
- Use samba or NFS for local file sharing.
- For SSHFS:
sshfs user@host:/path/to/share /local/mount/point
Unmount with:
sudo umount /local/mount/point
By following this guide, you can successfully set up a secure, functional file server, integrate powerful tools like Aria2 and AriaNG, and enable seamless file management both locally and remotely.
Comments