目录

[TOC]


1.查看nginx配置文件位置

/usr/sbin/nginx -t
root@server:/home/temp# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

可以看见默认配置文件的路径是:/etc/nginx/nginx.conf

2.添加自己的配置文件

/etc/nginx/sites-available目录下船舰一个自己的conf文件

vim /etc/nginx/sites-available/mysite.conf

完成写入后:wq保存退出

建立软连接激活配置文件

ln -s /etc/nginx/sites-available/mysite.conf /etc/nginx/sites-enabled

可以看见软连接已经创建成功:

root@server:/etc/nginx/sites-enabled# ls -la /etc/nginx/sites-enabled
total 8
drwxr-xr-x 2 root root 4096 Nov 26 22:17 .
drwxr-xr-x 9 root root 4096 Nov 26 22:15 ..
lrwxrwxrwx 1 root root   34 Nov 26 20:57 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root   36 Nov 26 22:17 emby.conf -> /etc/nginx/sites-available/emby.conf
root@server:/etc/nginx/sites-enabled#

也可以用nginx -c /etc/nginx/sites-available/mysite.conf手动选择配置文件

nginx -c /etc/nginx/sites-available/mysite.conf
注意:使用nginx -c后面需要跟绝对路径!!!
并且配置文件最好在/etc/nginx/里面

修改配置文件后需要保存修改

不一定非要用systemctl restart nginx.service
nginx -s reload也行

Last modification:November 27, 2022
V50%看看实力