nginx启动指定配置文件 007

815 阅读1分钟

nginx启动指定配置文件

要启动特定的nginx配置文件,可以使用以下命令:

nginx -c /path/to/nginx.conf

其中,/path/to/nginx.conf是你要使用的特定nginx配置文件的绝对路径。例如,如果要使用/etc/nginx/nginx.conf,则可以使用以下命令:

nginx -c /etc/nginx/nginx.conf

这将启动nginx并使用指定的配置文件。

另外,如果您希望在运行nginx时指定配置文件路径,可以通过编辑nginx的systemd unit文件来实现。例如,在Ubuntu系统上,可以运行以下命令编辑nginx的systemd单元文件:

sudo systemctl edit nginx.service

这会打开一个新的编辑器窗口,在其中添加以下内容:

[Service]
ExecStart=
ExecStart=/usr/sbin/nginx -c /path/to/nginx.conf

在这里,/path/to/nginx.conf是nginx配置文件的绝对路径。完成后,保存并关闭文件。然后,重新加载并启动nginx:

sudo systemctl daemon-reload
sudo systemctl restart nginx.service

这将重新加载nginx并使用新的指定配置文件启动它。