brew install nginx #安装
nginx #启动
nginx -s reload #重新加载
ps -ef|grep nginx #查看Nginx运行情况
kill -9 Nginx的master的ID #强制杀死Nginx进程
- 修改nginx配置文件,默认地址:/usr/local/etc/nginx/nginx.conf
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Test Nginx!</h1>
<form action="http://127.0.0.1:81/nginx" enctype="multipart/form-data" method="post">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit">
</form>
</body>
</html>
package main
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
app.Post("/nginx", func(ctx iris.Context) {
name := ctx.FormValue("username")
pw := ctx.FormValue("password")
ctx.JSON(map[string]interface{}{"a": name, "b": pw, "c":200}) //返回表单提交的内容
})
err := app.Run(iris.Addr(":81"))
if err != nil {
fmt.Println(err)
return
}
}
运行
- 后端项目启动
- Nginx启动
- 访问 http:localhost
- 提交表单
- 返回结果