以前比较习惯放在 /etc/nginx/
里,用 service nginx start
启动(对应 MacOS + brew 就是 /usr/local/etc/nginx/
和 brew services start nginx
)。来到我厂后,开始频繁接触 Nginx 和 OpenResty,现在觉得单独放在目录下面比较方便管理,所以改了一个出来。
配合 Makefile,方便日后使用:
- 启动服务
make run
- 关闭服务
make stop
- 重新加载
make reload
- 使用 php-fpm
- 代理上传资源(/wp-contents/uploads/)到真实服务器
- log 在本地
nginx = nginx
.PHONY: run
run:
mkdir -p logs
$(nginx) -p $$PWD -c nginx.conf
.PHONY: reload
reload: logs/nginx.pid all
$(nginx) -p $$PWD -c conf/nginx.conf -t
kill -HUP `cat $<`
.PHONY: reload
stop: logs/nginx.pid
$(nginx) -p $$PWD -c conf/nginx.conf -t
kill -QUIT `cat $<`
error_log logs/error.log error;
pid logs/nginx.pid;
events {
accept_mutex off;
}
http {
server {
listen 9010;
listen [::]:9010;
include /usr/local/etc/nginx/mime.types;
root /Users/meathill/Sites/wp-dev;
index index.php index.html index.htm index.nginx-debian.html;
server_name wp-dev.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
location /wp-content/uploads/ {
proxy_pass https://blog.meathill.com/wp-content/uploads/;
proxy_set_header Host blog.meathill.com;
proxy_ssl_name "blog.meathill.com";
proxy_ssl_server_name on;
}
location ~ \.php$ {
include /usr/local/etc/nginx/fastcgi.conf;
fastcgi_pass 127.0.0.1:9999;
}
}
}
代码放在 Github wp-dev-env
欢迎吐槽,共同进步