ubuntu搭建http文件服务器

搭建的过程

sudo apt install apache2

 

sudo apt install apache2

 

sudo apt install php

 

sudo apt-get install libapache2-mod-php

 

sudo /etc/init.d/apache2 restart

 

 

开启上传大文件的权限

 

cd /etc/php/php.ini

upload_max_filesize

post_max_size

再sudo /etc/init.d/apache2 restart

 

在/var/www/html 下创建以下两个文件和名称为upload/的文件夹

index.html的代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>All In Or Nothing</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>

    <body>
        <h1>All In Or Nothing</h1>
<hr />
<a href="/upload" target="_parent" >upload</a>
<p></p>
<a href="/download" target="_parent" >download</a>
<p></p>
<a href="/mini/index-php.html" target="_parent" >speedtest</a>
<p></p>

<form enctype="multipart/form-data" action="upload_file.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="300000000" />
Filename: <input name="file" type="file" /><br />
<input type="submit" value="Submit" />
</form>

<hr />

<p>Have a nice day!!!</p>

    </body>
</html>

 

 

php的代码

 

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }
if (file_exists("upload/" . $_FILES["file"]["name"]))
  {
  echo $_FILES["file"]["name"] . " already exists. ";
  }
else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);
  echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  }
?>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, I can help you with that! Here's a step-by-step guide to setting up an Nginx file server on Ubuntu 20.04: Step 1: Update System Packages Start by updating your system's package list by running the following command: ``` sudo apt update ``` Step 2: Install Nginx Next, install Nginx by running the following command: ``` sudo apt install nginx ``` Step 3: Configure Firewall If you have a firewall enabled (e.g., UFW), you'll need to allow HTTP traffic. Run the following command to allow it: ``` sudo ufw allow 'Nginx HTTP' ``` Step 4: Configure Nginx By default, Nginx is configured to serve files from the `/var/www/html` directory. You can edit the default configuration file using a text editor: ``` sudo nano /etc/nginx/sites-available/default ``` Inside this file, you can modify the `root` directive to specify the directory where you want to store your files. For example, if you want to use `/home/username/files` as your file directory, update the `root` directive as follows: ``` root /home/username/files; ``` Save the changes and exit the text editor. Step 5: Create File Directory Create the directory you specified in the Nginx configuration: ``` mkdir -p /home/username/files ``` Step 6: Adjust File Permissions To ensure that Nginx can access and serve the files, give the appropriate permissions to the directory: ``` sudo chown -R www-data:www-data /home/username/files ``` Step 7: Restart Nginx After making these changes, restart the Nginx service for the new configuration to take effect: ``` sudo systemctl restart nginx ``` Step 8: Upload Files Now, you can upload your files to the specified directory (`/home/username/files` in this example) using various methods like SCP, SFTP, or any other method you prefer. Step 9: Access Your Files You can access your files by navigating to your server's IP address or domain name in a web browser. For example, `http://your_server_ip` or `http://your_domain`. That's it! You have successfully set up an Nginx file server on Ubuntu 20.04.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值