使用Python启动一个简单的服务器[转]
首页 > Learning > Programming   作者:eehello  2019年6月1日 9:32 星期六  浏览:5485  字号:   评论:0 条
时间:2019-6-1 9:32   浏览:5485  评论:0 条 


转载自:https://www.cnblogs.com/weilantiankong/p/6140447.html


使用Python启动一个简单的服务器


在 Linux 服务器上或安装了 Python 的机器上,Python自带了一个WEB服务器 SimpleHTTPServer,我们可以很简单的使用  python -m SimpleHTTPServer 快速搭建一个http服务,提供一个文件浏览的web服务,而ios自带了 python,windows需要安装python才能使用。


1,当前目录发布到8001端口(明令后边的8001端口是可选的,不设置的话使用默认端口8000),该服务是前台运行的,control+c会关闭该服务。


python -m SimpleHTTPServer 8001


2,进程在后台运行,control+c不会关闭该服务,关闭bash时关闭服务。


python -m SimpleHTTPServer 8001 &


3,在命令的开头加一个nohup,忽略所有的挂断信号,如果当前bash关闭,则当前进程会挂载到init进程下,成为其子进程,这样即使退出当前用户,其8000端口也可以使用。


nohup python -m SimpleHTTPServer 8001 &


4,在浏览器访问:http://localhost:8001,如果当前文件夹有index.html文件,会默认显示该文件,否则,会以文件列表的形式显示目录下所有文件。




附送:


 npm start启动本地服务的方法


复制代码

// 项目目录执行

// npm install 安装依赖

// npm start 启动本地服务

// npm run build 打包资源到dist

{

  "name": "test",

  "version": "0.0.1",

  "description": "npm 启动本地服务的package.json配置",

  "main": "index.js",

  "scripts": {

    "start": "http-server ./ -p 8989 -e \"\" -c -1",

    "clean": "shx rm -rf ./dist && shx mkdir dist",

    "build": "npm run clean && shx cp -r *.html js css ./dist"

  },

  "devDependencies": {

    "http-server": "^0.9.0",

    "shx": "^0.1.4"

  }

}


附:


node 启动本地服务


npm install http-server -g 全局安装模块


package.json 里面配置脚本 "start": "http-server -a 0.0.0.0 -p 8000"


执行 npm start 启动服务


 您阅读这篇文章共花了: 
 本文没有标签!
二维码加载中...
本文作者:eehello      文章标题: 使用Python启动一个简单的服务器[转]
本文地址:https://www.eehello.com/?post=252
版权声明:若无注明,本文皆为“点滴记忆---观雨亭”原创,转载请保留文章出处。

返回顶部| 首页| 手气不错| 留言板|后花园

Copyright © 2014-2023 点滴记忆---观雨亭