在运行服务的开始/停止/重启nginx命令时调用OpenResty的nginx.conf文件。

我正在使用 nginx 作为我的 Django 项目的 Web 服务器。

我使用以下命令来管理 nginx 服务器:

sudo service nginx start/stop/restart

现在我正在使用 Openresty 框架将 Lua 代码实现到 nginx 服务器中来处理缓存系统。

Openrestry 提供了它自己的 nginx.conf 文件。

需求:现在我希望当我运行以下命令时:

sudo service nginx start/stop/restart

系统应该从 Openresty 文件夹中调用 nginx.conf 文件(/usr/local/openresty/nginx/conf/nginx.conf 替换 /etc/nginx/nginx.conf 文件)。

我如何实现此目标???

点赞
用户136008
用户136008

使用-c选项:

  -c filename   : 设置配置文件(默认值:/etc/nginx/nginx.conf)

例如:

sudo service nginx -c /usr/local/openresty/nginx/conf/nginx.conf start/stop/restart

你可以定义一个别名:

alias service_openresty="sudo service nginx -c /usr/local/openresty/nginx/conf/nginx.conf"

然后运行:

service_openresty start/stop/reload

这是唯一安全的方法,因为它不会被软件包更新覆盖。

2013-12-06 08:35:11
用户1850358
用户1850358

你应该前往

cd /etc/init.d
vim nginx.conf
#编辑 PATH , DAEMON 变量
PATH=/usr/local/openresty/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/openresty/nginx/sbin/nginx

现在,当你运行 sudo service nginx start/stop/restart 时,它将从 openresty 文件夹中调用 nginx.conf 文件。 而 /usr/local/openresty 是默认安装 Openresty 的路径。

2013-12-06 09:17:00
用户3069900
用户3069900

如果你想使用那个 Nginx 代替你的旧 Nginx,你可以在 "/etc/default/nginx" 中设置

DAEMON_OPTS=" -c usr/local/openresty/nginx/conf/nginx.conf "

在这种情况下,你可以像往常一样管理 Nginx

sudo service nginx start/stop/restart

但是,你在 /etc/nginx/nginx.conf 中的配置将无法生效。

2013-12-06 10:48:19
用户698544
用户698544

我知道这是一个旧的帖子,但 openresty 的作者(agentzh)建议通过将你的 /etc/init.d/nginx 复制到 /etc/init.d/openrestify 并修改路径以匹配你的自定义 openresty 安装来创建一个新的 openresty 服务。这是为了防止污染系统的默认配置文件。请查看这个邮件列表帖子

2014-08-25 22:07:34