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

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

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

a.建立nginx用户
[root@mysql-db01 conf]# useradd www -s /sbin/nologin -M
useradd: user 'nginx' already exists
b.查询nginx用户
[root@mysql-db01 conf]# id nginx
uid=497(nginx) gid=498(nginx) groups=498(nginx)
[root@mysql-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.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS 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]$ /data/nginx/sbin/nginx -c /home/lol/conf/nginx.conf
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /home/lol/conf/nginx.conf:5
##此处有警告,但是不影响nginx启动操作,如果有哪位能告诉我如何去除警告,先谢谢了。
[lol@mysql-db01 conf]$ ps -ef |grep nginx
lol 38719 1 0 23:15 ? 00:00:00 nginx: master process /data/nginx/sbin/nginx -c /home/lol/conf/nginx.conf
lol 38720 38719 0 23:15 ? 00:00:00 nginx: worker process
lol 38721 38719 0 23:15 ? 00:00:00 nginx: worker process
lol 38722 38719 0 23:15 ? 00:00:00 nginx: worker process
lol 38723 38719 0 23:15 ? 00:00:00 nginx: worker process
lol 38725 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]$

经过以上的配置就可以达到我们想要的降权启动nginx。但是这只是nginx优化的一个小部分。

Nginx降权启动的更多相关文章

  1. Tomcat降权启动

    对于任何降权的操作都是为了更好的保护自己的服务器免受危害,所以我们使用Tomcat也不了外,也需要进行降权操作.因为当 Tomcat以系统管理员身份或作为系统服务运行时,Java运行时取得了系统用户或 ...

  2. C/C++ 进程代码注入与提权/降权

    如果将shellcode注入到具有特定权限的进程中,我们就可以获得与该进程相同的权限,此方法可以用于提权与降权操作,注入有多种方式,最简单的是直接将metasploit生成的有效载荷直接注入到目标进程 ...

  3. Windows 安装nginx并开机启动

    Win安装nginx并 开机启动 下载nginx安装包 nginx-1.12.2.zip,解压到D盘. https://pan.baidu.com/s/1InQa527yq35Q68c73RBb-A# ...

  4. gitlab6 nginx配置和启动脚本

    gitlab6 nginx配置和启动脚本 cheungmine 2013-10 最近把gitlab安装到了ubuntu12.04.3的虚拟机上了.参考: https://github.com/gitl ...

  5. 利用系统函数模拟实现nginx 系统脚本启动的特殊颜色专业效果

    利用系统函数模拟实现nginx 系统脚本启动的特殊颜色专业效果/etc/init.d/nginxd {start/stop/restart/reload}利用if语句实现: ============= ...

  6. MSSQL和MYSQL数据库降权

    在服务器上如果是 system 用户在运行 MySQL ,这个是非常危险的,一旦Mysql 出现漏洞,或被其他模式提权,直接就是 system 权限.所以我们现在要给MySQL降权! 作用:增强服务器 ...

  7. Windows降权

    使用invoke-tokenmanipulation进行降权 枚举所有令牌 PS C:\Users\SMC> Get-ExecutionPolicy Restricted PS C:\Users ...

  8. Nginx服务器的启动控制

    写在前面的话:读书破万卷,编码如有神--------------------------------------------------------------------主要内容包括: nginx服 ...

  9. nginx环境下启动php-fpm

    nginx环境下启动php-fpm 1.首先查看是否安装了php-fpm 这个我试了好多命令都不行比如 rpm -qa php-fpm , rpm -ql php-fpm , which php-fp ...

随机推荐

  1. AOP称为面向切面编程,在程序开发中主要用来解决一些系统层面上的问题

    AOP称为面向切面编程,在程序开发中主要用来解决一些系统层面上的问题,比如日志,事务,权限等待,Struts2的拦截器设计就是基于AOP的思想,是个比较经典的例子. 一 AOP的基本概念 (1)Asp ...

  2. jQuery的Ajax操作小结——$.ajax和$.getJSON等用法小结

    一.$.ajax用法与举例 jQuery.ajax(url,[settings])     ——返回值:XMLHttpRequest 通过 HTTP 请求加载远程数据,这个是jQuery 的底层 AJ ...

  3. dom元素改变监听

    function domChange(domId, callback) { // select the target node var target = document.getElementById ...

  4. 基于SSH框架、Oracle数据库、easyui的分页显示

    要求:在easyui-datagrid中完成paginaton的分页功能. 1.easyui-datagrig的配置 <table id="dg" rownumbers=tr ...

  5. 【Java面试题】7 构造器Constructor是否可被override?

    构造器Constructor不能被继承,因此不能重写Override,但可以被重载Overload. Constructor不能被继承,所以Constructor也就不能被override.每一个类必 ...

  6. poj 3740 Easy Finding(Dancing Links)

    Easy Finding Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15668   Accepted: 4163 Des ...

  7. [Java并发包学习七]解密ThreadLocal

    概述 相信读者在网上也看了非常多关于ThreadLocal的资料,非常多博客都这样说:ThreadLocal为解决多线程程序的并发问题提供了一种新的思路:ThreadLocal的目的是为了解决多线程訪 ...

  8. 自定义HttpModule,用于未登录用户,不弹出Windows认证窗口,而是跳转回SSO站点

    2012年的一篇随笔记录,可以学习到如何自定义HttpModule,而具体里面针对需求开发的代码,可能未必能让大伙了解到什么,可快速扫描而过. using System; using System.W ...

  9. delphi7中添加QuickRep

    具体的方法是: delphi主菜单的Project|Options命令, 在Package选项卡的Desing packages列表中如果可以看到QuickReport Components选项, 那 ...

  10. SqlBulkCopy类进行大数据(10000万条以上)插入测试

    好多天没写博客了,刚刚毕业一个多月,在IT的路上真是迷茫啊! 关于上一篇博客中提到的,在进行批量数据插入数据库的时候可以通过给存储过程传递一个类型为Table的参数进行相关操作,在这个过程中本人没有进 ...