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

本文介绍了如何在Linux环境下,让普通用户sims20编译并启动Apache服务,同时解决由于权限不足无法绑定1024以下端口的问题。通过设置setuid权限,使Apache主进程以root权限运行,子进程以sims20用户运行,确保可以监听80端口。最后调整httpd.conf配置文件,确保安全性和权限设置正确。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

小编给大家分享一下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 install2、编译完成后,设置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 httpd5、重新进入普通用户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><h2>Forbidden</h2><p>You don't have permission to access /on this server.</p></body></html>报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 root9、再次用普通用户启动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 aspire11、再次用普通用户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 httpd12、试着访问一下 
[sims20@bcd-app01 bin]$ curl  http://10.248.12.159:80<html><body><h2>It works!</h2></body></html>成功了。


MPLS 中,数据传输发生在标签交换路径(LSP)上。LSP 是每一个沿着从源端到终端的路径上的结点的标签序列。现今使用着一些标签分发协议,如标签分发协议(LDP)、RSVP 或者建于路由协议之上的一些协议,如边界网关协议(BGP)及OSPF。因为固定长度标签被插入每一个包或信元的开始处,并且可被硬件用来在两个链接间快速交换包,所以使数据的快速交换成为可能。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值