diff --git a/sources/tech/20180411 How To Setup Static File Server Instantly.md b/sources/tech/20180411 How To Setup Static File Server Instantly.md deleted file mode 100644 index b925c75f1f..0000000000 --- a/sources/tech/20180411 How To Setup Static File Server Instantly.md +++ /dev/null @@ -1,173 +0,0 @@ -Transltaing by MjSeven - -How To Setup Static File Server Instantly -====== - -![](https://www.ostechnix.com/wp-content/uploads/2018/04/serve-720x340.png) -Ever wanted to share your files or project over network, but don’t know how to do? No worries! Here is a simple utility named **“serve”** to share your files instantly over network. This simple utility will instantly turn your system into a static file server, allowing you to serve your files over network. You can access the files from any devices regardless of their operating system. All you need is a web browser. This utility also can be used to serve static websites. It is formerly known as “list” and “micro-list”, but now the name has been changed to “serve”, which is much more suitable for the purpose of this utility. - -### Setup Static File Server Using Serve - -To install “serve”, you need to install NodeJS and NPM first. Refer the following link to install NodeJS and NPM in your Linux box. - -Once NodeJS and NPM installed, run the following command to install “serve”. -``` -$ npm install -g serve - -``` - -Done! Now is the time to serve the files or folders. - -The typical syntax to use “serve” is: -``` -$ serve [options] - -``` - -### Serve Specific files or folders - -For example, let us share the contents of the **Documents** directory. To do so, run: -``` -$ serve Documents/ - -``` - -Sample output would be: - -![][2] - -As you can see in the above screenshot, the contents of the given directory have been served over network via two URLs. - -To access the contents from the local system itself, all you have to do is open your web browser and navigate to **** URL. - -![][3] - -The Serve utility displays the contents of the given directory in a simple layout. You can download (right click on the files and choose “Save link as..”) or just view them in the browser. - -If you want to open local address automatically in the browser, use **-o** flag. -``` -$ serve -o Documents/ - -``` - -Once you run the above command, The Serve utility will open your web browser automatically and display the contents of the shared item. - -Similarly, to access the shared directory from a remote system over network, type **** in the browser’s address bar. Replace 192.168.43.192 with your system’s IP. - -**Serve contents via different port** - -As you may noticed, The serve utility uses port **5000** by default. So, make sure the port 5000 is allowed in your firewall or router. If it is blocked for some reason, you can serve the contents using different port using **-p** flag. -``` -$ serve -p 1234 Documents/ - -``` - -The above command will serve the contents of Documents directory via port **1234**. - -![][4] - -To serve a file, instead of a folder, just give it’s full path like below. -``` -$ serve Documents/Papers/notes.txt - -``` - -The contents of the shared directory can be accessed by any user on the network as long as they know the path. - -**Serve the entire $HOME directory** - -Open your Terminal and type: -``` -$ serve - -``` - -This will share the contents of your entire $HOME directory over network. - -To stop the sharing, press **CTRL+C**. - -**Serve selective files or folders** - -You may not want to share all files or directories, but only a few in a directory. You can do this by excluding the files or directories using **-i** flag. -``` -$ serve -i Downloads/ - -``` - -The above command will serve entire file system except **Downloads** directory. - -**Serve contents only on localhost** - -Sometimes, you want to serve the contents only on the local system itself, not on the entire network. To do so, use **-l** flag as shown below: -``` -$ serve -l Documents/ - -``` - -This command will serve the **Documents** directory only on localhost. - -![][5] - -This can be useful when you’re working on a shared server. All users in the in the system can access the share, but not the remote users. - -**Serve content using SSL** - -Since we serve the contents over the local network, we need not to use SSL. However, Serve utility has the ability to shares contents using SSL using **–ssl** flag. -``` -$ serve --ssl Documents/ - -``` - -![][6] - -To access the shares via web browser use “ or “. - -![][7] - -**Serve contents with authentication** - -In all above examples, we served the contents without any authentication. So anyone on the network can access them without any authentication. You might feel some contents should be accessed with username and password. - -To do so, use: -``` -$ SERVE_USER=ostechnix SERVE_PASSWORD=123456 serve --auth - -``` - -Now the users need to enter the username (i.e **ostechnix** in our case) and password (123456) to access the shares. - -![][8] - -The Serve utility has some other features, such as disable [**Gzip compression**][9], setup * CORS headers to allow requests from any origin, prevent copy address automatically to clipboard etc. You can read the complete help section by running the following command: -``` -$ serve help - -``` - -And, that’s all for now. Hope this helps. More good stuffs to come. Stay tuned! - -Cheers! - - - --------------------------------------------------------------------------------- - -via: https://www.ostechnix.com/how-to-setup-static-file-server-instantly/ - -作者:[SK][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) -选题:[lujun9972](https://github.com/lujun9972) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.ostechnix.com/author/sk/ -[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 -[2]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-1.png -[3]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-2.png -[4]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-4.png -[5]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-3.png -[6]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-6.png -[7]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-5-1.png -[8]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-7-1.png -[9]:https://www.ostechnix.com/how-to-compress-and-decompress-files-in-linux/ diff --git a/translated/tech/20180411 How To Setup Static File Server Instantly.md b/translated/tech/20180411 How To Setup Static File Server Instantly.md new file mode 100644 index 0000000000..9f31dba91e --- /dev/null +++ b/translated/tech/20180411 How To Setup Static File Server Instantly.md @@ -0,0 +1,161 @@ +如何设置一个即时静态文件服务器 +====== + +![](https://www.ostechnix.com/wp-content/uploads/2018/04/serve-720x340.png) + +曾经想通过网络共享你的文件或项目,但不知道怎么做?别担心!这里有一个名为 **serve** 的简单实用程序,可以通过网络即时共享你的文件。这个简单的实用程序会立即将你的系统变成一个静态文件服务器,允许你通过网络提供文件。你可以从任何设备访问这些文件,而不用担心它们的操作系统是什么。你所需的只是一个 Web 浏览器。这个实用程序还可以用来服务静态网站。它以前称为 “list” 或 “micri-list”,但现在名称已改为 “serve”,这更适合这个实用程序的目的。 + +### 使用 Serve 来设置一个静态文件服务器 + +要安装 "serve",首先你需要安装 NodeJS 和 NPM。参考以下链接在 Linux 中安装 NodeJS 和 NPM。 + + * [如何在 Linux 上安装 NodeJS](https://www.ostechnix.com/install-node-js-linux/) + +NodeJS 和 NPM 安装完成后,运行以下命令来安装 "serve": +``` +$ npm install -g serve +``` + +完成!现在是时候 serve 文件或文件夹了。 + +使用 "serve" 的典型语法是: +``` +$ serve [options] +``` + +### Serve 特定文件或文件夹 + +例如,让我们共享 **Documents** 目录里的内容。为此,运行: +``` +$ serve Documents/ +``` + +示例输出: +![][2] + +正如你在上图中看到的,给定目录的内容已通过两个 URL 提供网络支持。 + +要从本地系统访问内容,你只需打开 Web 浏览器,输入 **** URL: +![][3] + +Serve 实用程序以简单的布局显示给定目录的内容。你可以下载(右键单击文件并选择“将链接另存为...”)或只在浏览器中查看它们。 + +如果想要在浏览器中自动打开本地地址,使用 **-o** 选项。 +``` +$ serve -o Documents/ +``` + +运行上述命令后,Serve 实用程序将自动打开 Web 浏览器并显示共享项的内容。 + +同样,要通过网络从远程系统访问共享目录,可以在浏览器地址栏中输入 ****。用你系统的 IP 替换 192.168.43.192。 + +**通过不同的端口 Serve 内容** + +你可能已经注意到,默认情况下,serve 实用程序使用端口 **5000**。因此,确保防火墙或路由器中允许使用端口 5000。如果由于某种原因被阻止,你可以使用 **-p** 选项使用不同端口来提供内容。 +``` +$ serve -p 1234 Documents/ +``` + +上面的命令将通过端口 **1234** 提供 Documents 目录的内容。 +![][4] + +要提供文件而不是文件夹,只需给它完整的路径,如下所示。 +``` +$ serve Documents/Papers/notes.txt +``` + +只要知道路径,网络上的任何用户都可以访问共享目录的内容。 + +**Serve 整个 $HOME 目录** + +打开终端输入 +``` +$ serve +``` + +这将通过网络共享整个 $HOME 目录的内容。 + +要停止共享,按下 **CTRL+C**。 + +**Serve 选择的文件或文件夹** + +你可能不想共享所有文件或目录,只想共享其中的一些。你可以使用 **-i** 选项排除文件或目录。 +``` +$ serve -i Downloads/ +``` + +以上命令将 serve 整个文件系统,除了 **Downloads** 目录。 + +**仅在本地主机上提供内容** + +有时,你只想在本地系统而不是整个网络上 serve 内容。为此,使用 **-l** 标志,如下所示: +``` +$ serve -l Documents/ +``` + +此命令会仅在本地提供 **Documents** 目录。 + +![][5] + +当你在共享服务器上工作时,这可能会很有用。系统中的所有用户都可以访问共享,但远程用户不能。 + +**使用 SSL Serve 内容** + +由于我们通过本地网络 serve 内容,因此我们不需要使用 SSL。但是,serve 实用程序可以使用 **-ssl** 选项来使用 SSL 共享内容。 +``` +$ serve --ssl Documents/ +``` + +![][6] + +要通过 Web 浏览器访问共享,输入 “ 或 “. + +![][7] + +**通过身份验证 Serve 内容** + +在上面的所以示例中,我们在没有任何身份验证的情况下 serve 内容,所以网络上的任何人都可以在没有任何身份验证的情况下访问共享内容。你可能会觉得应该使用用户名和密码访问某些内容。 + +为此,使用: +``` +$ SERVE_USER=ostechnix SERVE_PASSWORD=123456 serve --auth +``` + +现在用户需要输入用户名(即 **ostechnix**)和密码(123456)来访问共享。(译者注:123456 是非常不好的密码,仅在实验情况下使用) + +![][8] + +Serve 实用程序还有一些其它功能,例如禁用 [**Gzip 压缩**][9],设置 **CORS** 头以允许来自任河源的请求,防止自动复制地址到剪贴板等。通过以下命令,你可以阅读完整的帮助部分。 +``` +$ serve help +``` + +好了,这就是全部了。希望这可以帮助到你。更多好东西要来了,敬请关注! + +共勉! + +来源: + + * [Serve GitHub 仓库](https://github.com/zeit/serve) + +-------------------------------------------------------------------------------- + +via: https://www.ostechnix.com/how-to-setup-static-file-server-instantly/ + +作者:[SK][a] +译者:[MjSeven](https://github.com/MjSeven) +校对:[校对者ID](https://github.com/校对者ID) +选题:[lujun9972](https://github.com/lujun9972) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.ostechnix.com/author/sk/ +[1]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 +[2]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-1.png +[3]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-2.png +[4]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-4.png +[5]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-3.png +[6]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-6.png +[7]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-5-1.png +[8]:http://www.ostechnix.com/wp-content/uploads/2018/04/serve-7-1.png +[9]:https://www.ostechnix.com/how-to-compress-and-decompress-files-in-linux/