记录1 极速建站 Linux python web.py http-server nginx

 一键架设(直接在你共享目录执行)
cd ../../../../../
pwd
mkdir /home/tweb
cd /home/tweb
curl -k https://gitee.com/py4u/lite-server/raw/master/web.sh -o web.sh && bash web.sh
pip install web.py==0.40.dev0  #这个好像很重要
在/etc/rc.d/rc.local文件中添加你要运行的命令.(开机运行脚本)
source /home/tweb/web.sh
sudo reboot            重启测试,至此布署完成,访问不成功请查防火墙.
nohup python -m http.server  80 > /dev/null 2> /dev/null &
下面是一个干净的http服务 端口.目录可轻松自定  建个文件/home/httpstar.py

#!/usr/bin/env python
#--coding:utf-8--
#
#在/etc/rc.d/rc.local文件中添加你要运行的命令.(开机运行脚本如下行)
#/usr/bin/python3 /home/httpstar.py > ./home/httpstar.log &
#12行 sep = '/tweb' #设置目录	55行	port = 80 #设置服务端口号
from http.server import BaseHTTPRequestHandler, HTTPServer
from os import path
from urllib.parse import urlparse

curdir = path.dirname(path.realpath(__file__))
sep = '/tweb' #设置目录

# MIME-TYPE
mimedic = [
						('.html', 'text/html'),
						('.htm', 'text/html'),
						('.js', 'application/javascript'),
						('.css', 'text/css'),
						('.json', 'application/json'),
						('.png', 'image/png'),
						('.jpg', 'image/jpeg'),
						('.gif', 'image/gif'),
						('.txt', 'text/plain'),
						('.avi', 'video/x-msvideo'),
					]

class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
	# GET
	def do_GET(self):
		sendReply = False
		querypath = urlparse(self.path)
		filepath, query = querypath.path, querypath.query
		
		if filepath.endswith('/'):
			filepath += 'index.html'
		filename, fileext = path.splitext(filepath)
		for e in mimedic:
			if e[0] == fileext:
				mimetype = e[1]
				sendReply = True

		if sendReply == True:
			try:
				with open(path.realpath(curdir + sep + filepath),'rb') as f:
					content = f.read()
					self.send_response(200)
					self.send_header('Content-type',mimetype)
					self.end_headers()
					self.wfile.write(content)
			except IOError:
				self.send_error(404,'File Not Found: %s' % self.path)

def run():
	port = 80 #设置服务端口号
	print('starting server, port', port)

	# Server settings
	server_address = ('', port)

	httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
	print('running server...')
	httpd.serve_forever()

if __name__ == '__main__':
	run()

Ubuntu  nginx安装
sudo apt-get install gcc g++ autoconf automake
sudo apt-get install build-essential
sudo apt-get update
sudo apt-get install wget
sudo apt update
sudo apt install nginx
/etc/init.d/nginx start  #启动服务
/etc/init.d/nginx restart #重启服务
多端口/etc/nginx/sites-available目录下编辑default

server {  #多段Server可建多网站
    listen 80; # 简单端口号
    listen 81; # 简单端口号
		#listen 192.168.0.15:808;#多网卡示例
		#listen 192.168.4.88:8098;#多网卡示例
	root /home/tweb; # 静态资源路径
	index index.html index.htm index.nginx-debian.html;
	server_name _;
	location / {
		try_files $uri $uri/ =404;
	}
}

你可能感兴趣的:(建站,ubuntu,http,linux,python,list)