nginx的常用配置修改
发布日期:2021-06-29 14:39:42 浏览次数:2 分类:技术文章

本文共 1442 字,大约阅读时间需要 4 分钟。

参考:https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms

参考:https://serverfault.com/questions/742482/getgrnamuser-failed-in-etc-nginx-nginx-conf
(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)

nginx的常用命令

a. 启动: nginx

b. 发送信号:nginx -s signal

Where signal may be one of the following:
stop — fast shutdown
quit — graceful shutdown
reload — reloading the configuration file
reopen — reopening the log files

c. 检查配置文件是否正常:nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

修改网站端口和home的指向

网站的端口通过server中的listen来修改,例如下面缺省的listen 80;

网站的home的指向,通过网站server中root来对应地址,例如下面的缺省对应的是:root /var/www/html;
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}

修改特定目录的指向

特定目录的指向与修改home的指向有类似的地方,也通过root来对应,不过是要指定某个location的root,例如下面的:

把访问/images/的路径指向/home目录,也即访问/home/images/来fetch相关的文件:
server {
location /images/ {
root /home;
}
}

修改nginx的读写的用户

在nginx.conf的开头缺省配置了:

user www-data;
以www-data的权限来访问相关的文件等内容,访问的权限对防护起作用。(个人理解,这块还并去查实际所起作用)
如果期望对它进行修改的话,可以采用如下方法:

a. 可以添加一个shell指向nologin的用户, 然后修改为新加用户:

useradd -d /var/rdata -s /usr/sbin/nologin -m rdata

b. 注意: 修改时, 一般需要同时指定user和group, 除非user和group同名情况.

例如: user rdata; 
等同于: user rdata rdata;

(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)

转载地址:https://chunyexiyu.blog.csdn.net/article/details/100609105 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:MFC窗口响应Enter/Esc
下一篇:nginx的重编过程

发表评论

最新留言

不错!
[***.144.177.141]2024年04月13日 10时52分32秒