程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Set up http file server (implemented by Python and nginx respectively)

編輯:Python

Use Python3

Windows and Linux Applicable to all platforms

Premise

Install well Python3 Environmental Science , And add the corresponding road strength to the environment variable

Enter... On the command line Python, You know Python Is the environment ready

python

If there are the following outputs , Just explain Python The environment is ready

Python 3.9.11 (tags/v3.9.11:2de452f, Mar 16 2022, 14:33:45) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>



Turn on HTTP File server

Switch the path to the destination folder

cd D:\code\note

Opening service , binding 8888 port
python -m http.server 8888



visit HTTP File server

Enter... In the browser

http://127.0.0.1:8888/

You can successfully visit our HTTP File server



Use Nginx

Apply to Linux platform

install Nginx

sudo apt install nginx

After installation , Enter the host in the browser IP, You can see the following interface

http://127.0.0.1




To configure

Configure the port and target path

server{

# Show directory 
autoindex on;
# Show file size 
autoindex_exact_size on;
# Show file time 
autoindex_localtime on;
# code 
charset utf-8;
# port 
listen 80;
server_name localhost;
# Local file path 
root /home/http_file_server;
location / {

# These files are downloaded, not browsed 
if ($request_filename ~* ^.*?.(txt|doc|pdf|rar|gz|zip|docx|exe|md|xls|bin|xlsx|ppt|pptx)$){

add_header Content-Disposition attachment;
}
}
}

Restart after configuration Nginx service

sudo systemctl reload nginx



visit HTTP File server

Enter... In the browser

http://127.0.0.1

You can successfully visit our HTTP File server


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved