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
![](https://i-blog.csdnimg.cn/blog_migrate/9a0ccc5494701532039cd78f84345ecd.jpeg)
<!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
}
}
运行
- 后端项目启动
![](https://i-blog.csdnimg.cn/blog_migrate/3f88f780fe9d01c42baeeb3bb3b07da3.jpeg)
- Nginx启动
- 访问 http:localhost
![](https://i-blog.csdnimg.cn/blog_migrate/a354d3c01766e7491ef27f8cffd23007.jpeg)
- 提交表单
![](https://i-blog.csdnimg.cn/blog_migrate/c6d1c3b7d9c8c94ef7f20f3c3cba3ec5.jpeg)
- 返回结果
![](https://i-blog.csdnimg.cn/blog_migrate/6ca24725b230ca3a0234b8db7b115ad3.jpeg)