您的位置:首页 > 运维架构 > Nginx

用普通用户运行nginx(安全优化)

2014-11-20 22:02 471 查看
一般情况下,我们在编译安装的时候会创建指定nginx来运行程序,但是nginx启动后它的master进程还是root,为了安全起见,我们要修改它的主进程,改为普通用户。
注意:普通进程就使用普通用户管理就可以,不要任何程序都使用root,一但出问题,很难搞!
检查:ps -ef

1、先创建一个普通用户;
useradd nginx-soft

2、要想使用普通用户运行nginx 必须要将端口80更改,大于1024,此处使用8000;
listen 8000;
index路径修改;
日志文件路径修改;
#端口可以使用sudo或者 nat 转换解决;

3、将/home/nginx-soft目录下的logs/conf/html/赋权给nginx-soft这一普通用户;
chown -R nginx-soft *
检查:drwxr-xr-x. 2 nginx-soft root 4096 Sep 11 13:23 conf
drwxr-xr-x. 2 nginx-soft root 4096 Sep 11 13:23 html
drwxr-xr-x. 2 nginx-soft root 4096 Sep 11 13:30 logs

4、使用root用户指定nginx的配置文件:
../nginx/sbin/nginx -s stop
../nginx/sbin/nginx -c /home/nginx-soft/conf/nginx.conf

5、切换至普通用户的宿主目录下;
将nginx主程序下的配置文件conf、html、logs文件拷贝到普通用户的加目录下;
cp -ap ../nginx1.6.2/conf/ .

cp -ap ../nginx1.6.2/html/ .

cp -ap ../nginx1.6.2/logs/ .
#此处注意html、logs、端口文件的配置

6、 切换到nginx-soft普通用户下启动nginx
ps -ef|grep nginx

本文出自 “思想大于技术” 博客,谢绝转载!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: