我有一个 Ansible playbook,用于配置一次性的 FreeBSD Jail,其中包含 nginx 的裸安装以及一些上游组件,例如 php-fpm。但有时你需要更简单的方法,以便在当前目录中进行一些快速测试。
假设您已经从您选择的包管理器安装了 nginx:
$ nginx -v ==> nginx version: nginx/1.27.5
这是我的轻量级nginx.conf
文件。我甚至不需要一个外部的mime.types
文件,因为它可能根据操作系统位于不同的位置,不过你可能更理性一些:
## Lightweight nginx.conf for local testing ## You would be wise not to use this in prod daemon off; worker_processes 1; events { worker_connections 4; } error_log error.log info; http { charset utf-8; types { application/atom+xml atom; application/rss+xml rss; application/javascript js; application/json json; image/gif gif; image/jpeg jpg; image/png png; image/svg+xml svg svgz; image/x-icon ico; text/html html htm; text/css css; text/plain txt; text/xml opml xml; } server { server_name localhost; listen 127.0.0.1:8080; root .; } }
然后运行一个小的server.sh
脚本来启动它。这将在同一目录中启动一个 nginx 服务器。
#!/usr/bin/env sh nginx -p $PWD -c ./nginx.conf
用我一位已故评论家的话来说,这真的没什么特别的,甚至没什么值得一提的。他在这方面绝对是对的。但我一直在用这个,所以就把它传下去,不管它值多少钱。
作者: Ruben Schade ,悉尼,2025 年 6 月 16 日。
原文: https://rubenerd.com/running-a-minimum-local-nginx-server/