千家信息网

apache在普通用户下启动的方法

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,小编给大家分享一下apache在普通用户下启动的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!目标:普通用户编译的apache,要在该用户下启动1024端口以下的apache端口。1
千家信息网最后更新 2026年11月01日apache在普通用户下启动的方法

小编给大家分享一下apache在普通用户下启动的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

目标:

普通用户编译的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:80no listening sockets available, shutting downUnable 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:80403 Forbidden

Forbidden

You don't have permission to access /on this server.

报403 Forbidden错误

7、看一下进程

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

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

8、在http.conf中配置一下,将用户改成root

User daemonGroup daemon

改成

User rootGroup root

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

[sims20@bcd-app01 bin]$ ./apachectl  restartSyntax 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

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

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

改成

User sims20Group aspire

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

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

12、试着访问一下

[sims20@bcd-app01 bin]$ curl  http://10.248.12.159:80

It works!

成功了。

看完了这篇文章,相信你对apache在普通用户下启动的方法有了一定的了解,想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!

用户 普通 权限 端口 编译 再次 进程 运行 配置 方法 篇文章 不行 特殊 成功 原因 参数 完了 更多 目标 知识 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 云南咖啡 与互联网科技公司 互联网科技股票 万易互联网科技有限公司 互联网科技美容 无锡溥仪互联网科技有限公司 互联网科技热点资讯 汽车互联网创新科技园 互联网金融科技公司干啥的 智腾互联网科技有限公司 健康食品互联网创新科技园项目 互联网科技大赛获奖感言 互联网科技圈年度人物 每天都有哪些好的互联网科技 智帮互联网科技公司最近动向 杭州披云加互联网科技有限公司 张召忠谈中国互联网科技 下一代互联网重大应用科技园 互联网科技接地气 山东亿川互联网科技有限责任公司 百单网互联网科技有限公司 善班互联网科技 科技创新互联网企业 西藏七维空间互联网科技有限公司 温州喔噻互联网科技有限公司 广西互联网科技孵化中心 互联网新科技动漫ppt素材 特约风豹互联网科技为什么扣费 互联网金融科技名词解释 山东有哪些互联网科技公司
0