Nginx降权启动

Nginx服务降权,用lol用户跑Nginx,给开发及运维设置普通账号,只要和lol同组即可管理Nginx,方案解决了Nginx管理问题,防止root分配权限过大。

开发人员使用普通账户即可管理Nginx站点以下程序问题。采取项目负责制制度,谁负责项目维护了问题谁负责。

 

1. 更改nginx默认用户及用户组(worker进程优化)

a.建立nginx用户
[root@mysql-db01 conf]#  useradd www -s /sbin/nologin -'nginx'-=497(nginx) gid=498(nginx) groups=498-db01 conf]#

2.配置nginx.conf使用nginx用户

user  www www;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;
.........

也可以编译的时候指定用户.

[root@mysql-db01 conf]# /application/nginx/sbin/nginx -V
nginx version: nginx/1.10.2built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013TLS SNI support enabled
configure arguments: --prefix=/application/nginx-1.10.2 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module

 

3.  让nginx运行于监牢模式

 这种方式简单来说就是为master服务降权:使用非root跑nginx master

注意:不能用80特权端口,前端nginx反向代理转端口在启动的时候指定配置文件,普通用户只能只用1024以上的端口。

[root@web01 ~]# useradd lol   ##创建普通用户
[root@web01 ~]# ll -ld /home/lol/drwx------ 2 inca inca 4096 Jul 31 18:19 /home/inca/[root@web01 ~]# 
[root@web01 ~]# su - lol    ##切换到普通用户下来进行下步操作

之所以要进入到普通用户下操作,是让普通用户对自己所创建的文件具有所有权

[inca@web01 ~]$ pwd/home/inca
[inca@web01 ~]$ mkdir conf  logs  www   ##创建必须的配置文件,日志,站点目录
[inca@web01 ~]$ cp /application/nginx/conf/mime.types ~/conf/    #拷贝配置文件中网页支持类型文件[inca@web01 ~]$ echo inca >www/index.html

拷贝原有配置文件nginx.conf并修改目录。

[inca@www ~]$ cat conf/nginx.conf 
worker_processes  4;
worker_cpu_affinity 0001 0010 0100 1000;
worker_rlimit_nofile 65535;
error_log  /home/lol/logs/error.log;
user www www;     
pid        /home/lol/logs/nginx.pid;
events {
    use epoll;
    worker_connections  10240;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';


    #web.fei fa dadong..............
    server {
        listen       8080;
        server_name  www.dadong.org 

;
        root   /home/lol/www;
        location / {
            index  index.php index.html index.htm;
                }
         access_log  /home/lol/logs/web_blog_access.log  main;
           }
}

 使用指定配置文件的方式启动nginx

[lol@web01 conf]$ -db01 conf]$ ps -ef |38719      1  0 23:15 ?        00:00:00 nginx: master process /data/nginx/sbin/nginx -c /home/lol/conf/38720  38719  0 23:15 ?        00:00:0038721  38719  0 23:15 ?        00:00:0038722  38719  0 23:15 ?        00:00:0038723  38719  0 23:15 ?        00:00:0038725  38685  0 23:15 pts/1    00:00:00 grep nginx

[lol@mysql-db01 conf]$ curl -I 10.0.0.51:8080
HTTP/1.1 200 OK
Server: nginx/1.10.2
Date: Mon, 06 Nov 2017 15:34:21 GMT
Content-Type: text/html
Content-Length: 5
Last-Modified: Mon, 06 Nov 2017 15:11:58 GMT
Connection: keep-alive
ETag: "5a007bbe-5"
Accept-Ranges: bytes

[lol@mysql-db01 conf]$ curl 10.0.0.51:8080
inca
[lol@mysql-db01 conf]$

报错的话说明 权限不对,把root的logs目录添加普通用户的权限 然后再启动 如果root的nginx  logs目录里有pid文件删掉











本文转自 蓝叶子Sheep 51CTO博客,原文链接:http://blog.51cto.com/dellinger/1981295,如需转载请自行联系原作者
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值