当前位置: 首页 > news >正文

zzw原创_非root用户启动apache的问题解决(非root用户启动apache的1024以下端口)

场景:普通用户编译的apache,要在该用户下启动1024端口以下的apache端口

1、假设普通用户为sims20,用该用户编译 安装了一个apache,安装路径为/opt/aspire/product/sims20/apache

    ./configure --prefix=/opt/aspire/product/sims20/apache   --enable-so --enable-modules=all   --enable-mods-shared=all   --enable-mods-shared='proxy proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http proxy_rewrite'

  make
  make install

2、编译完成后,设置http.conf的监听端口为80

3、直接用普通用户sims20启动

  [sims20@bcd-app01 bin]$ ./apachectl  start
(13)Permission denied: make_sock: could not bind to address [::]:80
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

     出错原因:在linux下,普通用户只能用1024以上的端口,而1024以内的端口只能由root用户才可以使用

4、利用setuid来解决问题,这样使用httpd能以root权限运行

      用root用户登录,进入/opt/aspire/product/sims20/apache/bin,分别用chown root  httpd、chmod u+s httpd 设置httpd的属主为root及特殊权限

[root@bcd-app01 bin]# ls  -l  httpd
-rwxr-xr-x 1 sims20 aspire 3517470  3月 15 17:12 httpd
[root@bcd-app01 bin]# chown root  httpd
[root@bcd-app01 bin]# ls  -l  httpd
-rwxr-xr-x 1 root aspire 3517470  3月 15 17:12 httpd
[root@bcd-app01 bin]# chmod u+s httpd
[root@bcd-app01 bin]# ls  -l  httpd
-rwsr-xr-x 1 root aspire 3517470  3月 15 17:12 httpd

5、重新进入普通用户sims20,启动apache

          [sims20@bcd-app01 bin]$ ./apachectl  start

        可以正常启动,没报错

6、试着访问一下

 [sims20@bcd-app01 bin]$ curl  http://10.24.12.159:80
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /
on this server.</p>
</body></html>

报403 Forbidden错误

7、看一下进程

[sims20@bcd-app01 bin]$ ps  -ef |grep httpd
root      7841     1  0 17:24 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
daemon    7844  7841  0 17:24 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
daemon    7845  7841  0 17:24 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
daemon    7846  7841  0 17:24 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
daemon    7847  7841  0 17:24 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
daemon    7848  7841  0 17:24 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
sims20    8006  3026  0 17:29 pts/4    00:00:00 grep httpd

怎么跑出daemon 用户了,  原来httpd主进程仍然以root用户的权限运行,而它的子进程将以一个较低权限的用户运行 ,而这个较低权限用户daemon 在http.conf中配置

 

7、在http.conf中配置一下,将用户改成root
   User daemon
   Group daemon

    改成
    User root
    Group root

8、再次用普通用户启动apache

   [sims20@bcd-app01 bin]$ ./apachectl  restart
Syntax error on line 76 of /opt/aspire/product/sims20/apache/conf/httpd.conf:
Error:\tApache has not been designed to serve pages while\n\trunning as root.  There are known race conditions that\n\twill allow any local user to read any file on the system.\n\tIf you still desire to serve pages as root then\n\tadd -DBIG_SECURITY_HOLE to the CFLAGS env variable\n\tand then rebuild the server.\n\tIt is strongly suggested that you instead modify the User\n\tdirective in your httpd.conf file to list a non-root\n\tuser.\n


不行的,要重新加参数编译

9、再次修改在http.conf中配置一下,将用户改成普通用户吧

    改成
    User sims20
    Group aspire

10、再次用普通用户sims20启动apache

[sims20@bcd-app01 bin]$ ./apachectl  start
[sims20@bcd-app01 bin]$ ps  -ef  |grep  httpd
root      9720     1  0 18:09 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
sims20    9721  9720  0 18:09 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
sims20    9722  9720  0 18:09 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
sims20    9723  9720  0 18:09 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
sims20    9724  9720  0 18:09 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
sims20    9725  9720  0 18:09 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k start
sims20    9739  3026  0 18:09 pts/4    00:00:00 grep httpd

6、试着访问一下

[sims20@bcd-app01 bin]$ curl  http://10.248.12.159:80
<html><body><h1>It works!</h1></body></html>

    成功了

转载于:https://www.cnblogs.com/zzw-zyba/p/8575428.html

相关文章:

  • SQL循环语句 详解
  • OpenCV问题集锦
  • 20154327 Exp1 PC平台逆向破解
  • ios 通知与通知传值2018.03.17
  • 20155307《网络对抗》PC平台逆向破解(二)
  • 273. Integer to English Words
  • DevOps是一种文化,不是角色!
  • 00004、python+selenium 的三种时间等待方式
  • SQL SERVER存储过程一
  • HTML中nbsp; ensp; emsp; thinsp;等6种空白空格的区别
  • P1280 尼克的任务
  • 动态代理和AOP
  • php 实现SFTP上传文件
  • WordCount项目总结
  • 2017校招真题在线编程- 网易 合唱团
  • 「前端早读君006」移动开发必备:那些玩转H5的小技巧
  • Android优雅地处理按钮重复点击
  • Apache的基本使用
  • es的写入过程
  • learning koa2.x
  • Leetcode 27 Remove Element
  • Linux快速复制或删除大量小文件
  • Linux学习笔记6-使用fdisk进行磁盘管理
  • vue2.0一起在懵逼的海洋里越陷越深(四)
  • vue中实现单选
  • 动手做个聊天室,前端工程师百无聊赖的人生
  • 关于List、List?、ListObject的区别
  • 关于使用markdown的方法(引自CSDN教程)
  • 目录与文件属性:编写ls
  • 使用Maven插件构建SpringBoot项目,生成Docker镜像push到DockerHub上
  • 再谈express与koa的对比
  • 测评:对于写作的人来说,Markdown是你最好的朋友 ...
  • # include “ “ 和 # include < >两者的区别
  • ###STL(标准模板库)
  • #define用法
  • #我与Java虚拟机的故事#连载13:有这本书就够了
  • $(function(){})与(function($){....})(jQuery)的区别
  • (1)(1.13) SiK无线电高级配置(五)
  • (1)安装hadoop之虚拟机准备(配置IP与主机名)
  • (22)C#传智:复习,多态虚方法抽象类接口,静态类,String与StringBuilder,集合泛型List与Dictionary,文件类,结构与类的区别
  • (solr系列:一)使用tomcat部署solr服务
  • (vue)页面文件上传获取:action地址
  • (ZT)薛涌:谈贫说富
  • (搬运以学习)flask 上下文的实现
  • (二)斐波那契Fabonacci函数
  • (附源码)ssm经济信息门户网站 毕业设计 141634
  • (附源码)基于ssm的模具配件账单管理系统 毕业设计 081848
  • (转)IOS中获取各种文件的目录路径的方法
  • (转)详解PHP处理密码的几种方式
  • (转贴)用VML开发工作流设计器 UCML.NET工作流管理系统
  • .net core 3.0 linux,.NET Core 3.0 的新增功能
  • .net 中viewstate的原理和使用
  • .NET/C# 获取一个正在运行的进程的命令行参数
  • .NET/C# 使窗口永不获得焦点
  • .Net程序猿乐Android发展---(10)框架布局FrameLayout