Nginx降权启动
给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降权启动的更多相关文章
- Tomcat降权启动
对于任何降权的操作都是为了更好的保护自己的服务器免受危害,所以我们使用Tomcat也不了外,也需要进行降权操作.因为当 Tomcat以系统管理员身份或作为系统服务运行时,Java运行时取得了系统用户或 ...
- C/C++ 进程代码注入与提权/降权
如果将shellcode注入到具有特定权限的进程中,我们就可以获得与该进程相同的权限,此方法可以用于提权与降权操作,注入有多种方式,最简单的是直接将metasploit生成的有效载荷直接注入到目标进程 ...
- Windows 安装nginx并开机启动
Win安装nginx并 开机启动 下载nginx安装包 nginx-1.12.2.zip,解压到D盘. https://pan.baidu.com/s/1InQa527yq35Q68c73RBb-A# ...
- gitlab6 nginx配置和启动脚本
gitlab6 nginx配置和启动脚本 cheungmine 2013-10 最近把gitlab安装到了ubuntu12.04.3的虚拟机上了.参考: https://github.com/gitl ...
- 利用系统函数模拟实现nginx 系统脚本启动的特殊颜色专业效果
利用系统函数模拟实现nginx 系统脚本启动的特殊颜色专业效果/etc/init.d/nginxd {start/stop/restart/reload}利用if语句实现: ============= ...
- MSSQL和MYSQL数据库降权
在服务器上如果是 system 用户在运行 MySQL ,这个是非常危险的,一旦Mysql 出现漏洞,或被其他模式提权,直接就是 system 权限.所以我们现在要给MySQL降权! 作用:增强服务器 ...
- Windows降权
使用invoke-tokenmanipulation进行降权 枚举所有令牌 PS C:\Users\SMC> Get-ExecutionPolicy Restricted PS C:\Users ...
- Nginx服务器的启动控制
写在前面的话:读书破万卷,编码如有神--------------------------------------------------------------------主要内容包括: nginx服 ...
- nginx环境下启动php-fpm
nginx环境下启动php-fpm 1.首先查看是否安装了php-fpm 这个我试了好多命令都不行比如 rpm -qa php-fpm , rpm -ql php-fpm , which php-fp ...
随机推荐
- java中main函数解析
从写java至今,写的最多的可能就是主函数 public static void main(String[] args) {} 但是以前一直都没有问自己,为什么要这么写,因为在c语言中就没有这样子的要 ...
- Mac之安装zsh
1.安装homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/in ...
- VS2008兼容安装
1. 直接安装出现问题:该项目的所有配置都需要系统提供对某些 平台的支持,但在此计算机上没有安装这些平台.因此无法加载该项目. 解决方法:先卸载原来安装的, 再设置安装包中的setup.exe的兼容性 ...
- 使用 const 提高函数的健壮性
使用 const 提高函数的健壮性 看到 const 关键字,C++程序员首先想到的可能是 const 常量.这可不是良好的条件 反射.如果只知道用 const 定义常量,那么相当于把火药仅用于制作 ...
- html -- 实体
- 转载:mysql如果数据不存在,则插入新数据,否则更新的实现方法
转自:http://www.jb51.net/article/28885.htm //如果不存在,则插入新数据 $sql = "INSERT INTO {$ecs->table(‘ca ...
- linux下简单好用的端口映射转发工具rinetd 转
linux下简单好用的工具rinetd,实现端口映射/转发/重定向 官网地址http://www.boutell.com/rinetd 软件下载 wget http://www.boutell.com ...
- CentOS下 Uptime 命令
对于一些人来说系统运行了多久是无关紧要的,但是对于服务器管理员来说,这是相当重要的信息.服务器在运行重要应用的时候,必须尽量保证长时间的稳定运行,有时候甚至要求零宕机.那么我们怎么才能知道服务器运行了 ...
- 【Java NIO的深入研究6】JAVA NIO之Scatter/Gather
Java NIO开始支持scatter/gather,scatter/gather用于描述从Channel(译者注:Channel在中文经常翻译为通道)中读取或者写入到Channel的操作. 分散(s ...
- Python使用paramiko库远程安全连接SSH
#!/usr/bin/python #ssh import paramiko import sys,os host='127.0.0.1' user = 'whl' password = ' s = ...