使用各种语言框架搭建http服务器

为什么这么做

仅是一个简单的个人收藏,希望能把所有语言集成的httpweb服务,全部打包起来学习,在合适的场景下使用对应的开发方式。

nginx

编辑nginx.conf文件vim /usr/local/nginx/conf/nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html/public;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

golang-gin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package main

import (
"net/http"
"github.com/gin-gonic/gin"
)

func main() {
router := gin.Default()
// Static只能展示文件
router.Static("/", "./public/")
// StaticFS可以连目录也一起展示
// router.StaticFS("/", http.Dir("./public/"))
// StaticFile展示单个文件
// router.StaticFile("/favicon.ico", "./resources/favicon.ico")
router.NoRoute(func(context *gin.Context) {
context.Header("Content-Type", "text/html; charset=utf-8")
context.String(http.StatusOK, "<h3>访问的页面不存在</h3>")
})
router.Run(":80")
}

使用go mod init初始化模块,创建go.mod文件。在开发和发布新模块时使用,用于管理模块依赖。
使用go mod tidy整理模块依赖,移除不需要的依赖。在开发和测试阶段使用,用于管理模块依赖。
使用go get <依赖路径>下载并安装指定的包和依赖项。它会自动下载所需的依赖项,并将它们安装到$GOPATH目录下。
使用go mod download <依赖路径>执行该命令之后,Go 会自动下载并安装依赖,安装后的依赖在 $GOPATH/pkg/mod 目录下。

java-Springboot

只需要在application.properties加一句

1
spring.resources.static-locations=file:./static/,classpath:/static/

最后在vscode中图片上传如何做

图片快捷上传
用vscode picgo插件,直接在vscode中搜索picgo插件,然后配置好oss的accesskeyID和accesskeySecret等配置,之后复制一张图片,在markdown文件里面按ctrl+alt+u就可以上传这个文件,并自动生成markdown图片格式,在预览markdown里面显示出来。

picgo配置如下
20230409132004

Author: chacebai
Link: http://www.spyhex.com/2022/httpserver-programer-anymore/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.