linux服务之httpd

http://mirrors.cnnic.cn/apache/httpd/docs/  英文pdf文档下载

 

Apache HTTP Project’s goal

It is the Apache HTTP Project’s first goal to create a robust and correct implementation of the HTTP server RFC. Additional goals include security, scalability and optimization.

 预分支(Pre-Forking)模型 Unix上的Apache是应用了预分支模型的服务器。父进程的责任仅在于繁衍子进程,它从不响应来自socket的任何请求。

ServerRoot    指的是配置文件根
DocumentRoot    指的是网页文件根

 

两种消息类型都由,4部分组成
1.开始行,说明是请求或是应答
GET /geo/geo.js HTTP/1.1\r\n
HTTP/1.1 200 OK\r\n

2.零个或多个字段头也叫headers
Host: api.g-fox.cn\r\n
Accept: */*\r\n

Server: nginx\r\n
Date: Sun, 06 Dec 2015 02:26:31 GMT\r\n

3.空行CRLF,指示headers结束
\r\n
4.可能有消息体

 

清除firefox 单站点缓存

其实在“管理所有历史记录”里面可以,在某一个记录上右键——清除此站点信息

 

测试配置文件的语法

14:12:03 97 /etc/httpd/conf:#apachectl -t -f /etc/httpd/conf/new.conf
httpd: Syntax error on line 2 of /etc/httpd/conf/new.conf: Include takes one argument, Name of the config file to be included
14:12:17 98 /etc/httpd/conf:#apachectl -t -f /etc/httpd/conf/httpd.conf
Syntax OK

 

 

 

 

webspace path

filesystem path

 

所以最后总结出要更改配置文件,不要在/etc/httpd/conf/httpd.conf上变动,而是在/etc/httpd/conf.d/下面新建*.conf文件来操作

 

编码问题

今天从这篇文章中学习了apache关于defaultcharset的设置和优先级的问题。

1.页面没有指定charset , Apache配置defaultcharset gbk , 页面文件编码是utf-8。

  执行结果是页面乱码。这个几乎是肯定的,在页面没有meta指明charset,而服务器的defaultcharset又没有被注释掉,可以肯定页面是会乱码的,这个时候服务器的设置生效;


2.页面指定charset为utf-8,  Apache配置defaultcharset  gbk. 页面文件是utf-8。

  执行结果是页面乱码。这个就验证了当服务器的defaultcharset打开时,会忽略掉页面的编码设置;

3.PHP header申明charset为utf8, Apache配置defaultcharst gbk,页面文件编码是utf8。

  执行结果是页面正常。这个说明header中指定的信息的优先级要高于服务器及浏览器的设置;

4.Apache设置DefaultCharset off。

  页面显示正常。


当且仅当应答内容是text/plain或text/html时,此指令将会在HTTP应答头中加入的默认字符集。理论上这将覆盖在文档体中通过<meta>标 签指定的字符集,但是实际的行为通常取决于用户浏览器的设置。AddDefaultCharset Off 将会禁用此功能。 AddDefaultCharset On 将启用Apache内部的默认字符集iso-8859-1 。您也可以指定使用在IANA注册过的字符集名字 中的另外一个charset 。比如说:

AddDefaultCharset utf-8 


如果服务器和页面都没有指定编码,我想这时编码是由浏览器的默认编码来确定的,这时Firefox和IE就会发生区别,当然是指安装在中文系统里的浏览器,如果系统不同我想结果还会有差异。

 

 

[root@localhost ~]# httpd -l
Compiled in modules:
  core.c
  prefork.c
  http_core.c
  mod_so.c

C:\Apache22\bin>httpd.exe -l
Compiled in modules:
  core.c
  mod_win32.c
  mpm_winnt.c
  http_core.c
  mod_so.c

 

伪静态

针对此版本的Discuz_X3.2_SC_UTF8.zip

URL 静态化是一个利于搜索引擎的设置,通过 URL 静态化,达到原来是动态的 PHP 页面转换为静态化的 HTML 页面,当然,这里的静态化是一种假静态,目的只是提高搜索引擎的搜索量,Comsenz 旗下的产品 Discuz!、SupeSite/X-Space、ECShop、SupeV、UCHome 等都支持此功能。当然这个功能还需要服务器环境的支持,下面介绍一下如何在 Apache 服务器下配置 URL 静态化的 Rewrite 规则。

步骤:
用管理员登录后台,全局》SEO优化》URL静态化》勾选-提交-查看当前的 Rewrite 规则
会出现一个页面,有6部分,复制对应的内容,粘贴到/etc/httpd/conf/httpd.conf中,然后重启httpd,就可生效。
也就是说如果是Apache Web Server(独立主机用户),就复制它下面的内容。如果是其它,就复制其它的内容。

 

 目录浏览

开启目录浏览

目录浏览功能就是可以让在没有索引文件的状态下实现浏览当前目录下的所有文件及目录,下面我们一起来看看apache开启目录浏览功能的方法,希望例子能够帮助到各位。

不管哪个目录,如果没有directoryindex 指令后面的文件名,就是开启了浏览功能,不需要加options indexes指令

根目录浏览

开启根目录浏览,只需要关闭#Include conf.d/*.conf这行即可,或者注释掉welcome.conf中的内容(一般选这个),如果根下无index.html或其它索引文件,会默认列出目录,要禁止的话

加上options -indexes指令,其它的目录都可以加以保护,参看访问控制与认证授权

别名目录浏览


定义一个别名,并且在lib64有问题时,可以重定向到别处
LoadModule autoindex_module modules/mod_autoindex.so LoadModule dir_module modules/mod_dir.so

alias /dist "/lib64"
<Directory "/lib64/">
    Options indexes FollowSymLinks
#    Options -indexes FollowSymLinks
    IndexOptions NameWidth=10 Charset=UTF-8
    Redirect permanent /dist/ http://172.16.1.47/tt/
</Directory>

 

 

LoadModule autoindex_module modules/mod_autoindex.so
DirectoryIndex index.php default.php index.html index.html.var

 

per-user web

[Thu Nov 12 09:04:29 2015] [error] [client 192.168.1.88] File does not exist: /var/www/html/~a1

useradd a1
passwd a1
登录一次
mkdir public_html
echo "a1111111" > public_html/index.html
chmod 711 public_html

在httpd.conf中添加
<IfModule mod_userdir.c>
    UserDir public_html
</IfModule>
userdir指令的context是server config和virtual host,不能用在dirctory中,参看文档的该指令描述
即可,如果还要细化控制,再添加如下
#<Directory /home/*/public_html>
#    AllowOverride FileInfo AuthConfig Limit
#    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
#    <Limit GET POST OPTIONS>
#        Order allow,deny
#        Allow from all
#    </Limit>
#    <LimitExcept GET POST OPTIONS>
#        Order deny,allow
#        Deny from all
#    </LimitExcept>
#</Directory>

apache -k restart
浏览器访问http://192.168.1.47/~a1测试效果

 

webdav

[Thu Nov 12 09:10:50 2015] [error] [client 192.168.1.88] (13)Permission denied: access to /webdav denied

LoadModule dav_module modules/mod_dav.so
LoadModule dav_fs_module modules/mod_dav_fs.so

webdav与per user web一样,只能在server config 或virtual host中配置,即只能在httpd.conf中配置,否则不生效
在httpd.conf中添加如下
<IfModule mod_dav_fs.c>
    # Location of the WebDAV lock database.
    DAVLockDB /var/lib/dav/lockdb
</IfModule>

Alias /webdav "/home/a1/"
<Directory "/home/a1/">
Dav On
</Directory>
lockdb路径可以任意,成功连接之后,会自动创建如下文件
[root@localhost conf.d]# ll /var/lib/dav/
total 4
-rw-r--r-- 1 apache apache    0 Nov 12 10:36 lockdb.dir
-rw-r--r-- 1 apache apache 1024 Nov 12 10:38 lockdb.pag
apache -k restart
在win7计算机中映射网络驱动器 \\172.16.1.47\webdav 添加成功,然后就可以上传网站文件,修改测试非常方便

 

 

Authentication is any process by which you verify that someone is who they claim they are. 
Authorization is any process by which someone is allowed to be where they want to go, or to have information that they want to have.
(For general access control, see the Access Control How-To (p. 208) )
Access control refers to any means of controlling access to any resource.

 访问控制

访问控制 access control by host

先搞清楚是拒绝优先,还是允许优先,确定以后,就可以设置顺序了
只拒绝这个ip,其它允许
order deny,allow
deny from 192.168.1.65

只允许这个网段,其它全部禁止
order allow,deny
allow from 172.16.1.0/25

LoadModule authz_host_module modules/mod_authz_host.so
三个指令
allow
deny
order

访问控制 access control by environment variable
LoadModule setenvif_module modules/mod_setenvif.so

 认证授权 file,dbm,.htaccess

个别目录需要认证的话,在要保护的目录下使用.htaccess文件较灵活,但如果多个目录的话,一次写入<directory>较方便

先创建密码文件
[root@localhost conf.d]# htpasswd -c us fgy
New password:
Re-type new password:
Adding password for user fgy
添加新用户
[root@localhost conf.d]# htpasswd us ken
New password:
Re-type new password:
Adding password for user ken
[root@localhost conf.d]# cat us
fgy:wOFUYK2pU5Cm6
ken:RjZTIeFiLO6mU
没有删除用户的操作,直接将us里的相应行删除即可

基本认证授权的两种方法
一是在directory中设置
二是在.htaccess文件中设置,将其放入想要保护的目录中即可

authtype basic/digest 但是并非所有的浏览器都支持摘要认证 require user ken 单用户或多用户
require valid-user 所有用户

在相应的directory中添加如下即可,authname名称无所谓 authname oo authtype basic authuserfile /etc/httpd/conf.d/us require valid-user
1.将上面的4行放入.htaccess文件中, 2.并在相应的<directory>中只添加allowoverride all这一行 3.重启apache .htaccess文件又称为“分布式配置文件”,该文件可以覆盖httpd.conf文件中的配置,但是它只能设置对目录的访问控制和用户认证。.htaccess文件可以有多个,每个.htaccess文件的作用范围仅限于该文件所存放的目录以及该目录下的所有子目录。虽然.htaccess能实现的功能在<Directory>段中都能够实现,但是因为在.htaccess修改配置后并不需要重启Apache服务就能生效,所以在一些对停机时间要求较高的系统中可以使用。



创建密码文件
[root@localhost conf.d]# htdbm -c dbm1 fgy1
Enter password        :
Re-type password      :
Database dbm1 created.
修改用户密码
[root@localhost conf.d]# htdbm dbm1 fgy1
Enter password        :
Re-type password      :
Database dbm1 modified.
添加用户
[root@localhost conf.d]# htdbm dbm1 fgy2
Enter password        :
Re-type password      :
Database dbm1 updated.
删除用户
[root@localhost conf.d]# htdbm -x dbm1 fgy4
Database dbm1 modified.
列出用户
[root@localhost conf.d]# htdbm  -l dbm1
Dumping records from database -- dbm1
    Username                         Comment
    fgy1
Total #records : 1

[root@localhost conf.d]# ll
total 20
-rw-r--r--. 1 root root    0 Nov 11 16:12 dbm1.dir
-rw-r--r--. 1 root root 1024 Nov 11 16:13 dbm1.pag
-rw-r--r--. 1 root root  392 Aug 25 01:53 README
-rw-r--r--. 1 root root  496 Nov 11 16:12 test.conf
-rw-r--r--. 1 root root   36 Nov 11 13:59 us
-rw-r--r--. 1 root root  303 Nov 11 10:34 welcome.conf
[root@localhost conf.d]# apachectl -k restart
[root@localhost conf.d]# vi test.conf
alias /dir "/etc"
<directory "/etc/">
authname "dbmmange"
authtype basic
authbasicprovider dbm
authdbmuserfile /etc/httpd/conf.d/dbm1
require valid-user
</directory>

 

ldap

LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so

 

 

 性能测试

14:23:55 20 ~:#ab -n 50 localhost/etc
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software:        Apache/2.2.15
Server Hostname:        localhost
Server Port:            80

Document Path:          /etc
Document Length:        201 bytes

Concurrency Level:      1
Time taken for tests:   0.015 seconds
Complete requests:      50
Failed requests:        0
Write errors:           0
Non-2xx responses:      50
Total transferred:      19050 bytes
HTML transferred:       10050 bytes
Requests per second:    3328.67 [#/sec] (mean)
Time per request:       0.300 [ms] (mean)
Time per request:       0.300 [ms] (mean, across all concurrent requests)
Transfer rate:          1238.50 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    0   0.3      0       2
Waiting:        0    0   0.1      0       1
Total:          0    0   0.3      0       2

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      0
  95%      0
  98%      2
  99%      2
 100%      2 (longest request)



14:26:05 23 ~:#ab -n 500 http://172.16.1.42/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.16.1.42 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests


Server Software:        nginx/1.4.7
Server Hostname:        172.16.1.42
Server Port:            80

Document Path:          /
Document Length:        168 bytes

Concurrency Level:      1
Time taken for tests:   0.153 seconds
Complete requests:      500
Failed requests:        0
Write errors:           0
Non-2xx responses:      500
Total transferred:      158500 bytes
HTML transferred:       84000 bytes
Requests per second:    3259.18 [#/sec] (mean)
Time per request:       0.307 [ms] (mean)
Time per request:       0.307 [ms] (mean, across all concurrent requests)
Transfer rate:          1008.94 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     0    0   0.0      0       1
Waiting:        0    0   0.0      0       1
Total:          0    0   0.1      0       1

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      0
  95%      0
  98%      1
  99%      1
 100%      1 (longest request)


 

 日志记录

定义了4个昵称
combined
common
referer
agent
combinedio

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

192.168.2.80 - - [07/Apr/2015:14:34:50 +0800] "GET /docs/ HTTP/1.1" 200 1664 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
192.168.2.80 - - [07/Apr/2015:14:34:53 +0800] "GET /docs/html/ HTTP/1.1" 200 17621 "http://192.168.2.84/docs/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
192.168.2.80 - - [07/Apr/2015:14:34:55 +0800] "GET /docs/html/manual.css HTTP/1.1" 404 296 "http://192.168.2.84/docs/html/basics.html" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
192.168.2.80 - - [07/Apr/2015:14:34:58 +0800] "GET /docs/html/graph_overview.html HTTP/1.1" 200 3693 "http://192.168.2.84/docs/html/basics.html" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
192.168.2.80 - - [07/Apr/2015:14:34:58 +0800] "GET /docs/html/manual.css HTTP/1.1" 404 296 "http://192.168.2.84/docs/html/graph_overview.html" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
192.168.2.80 - - [07/Apr/2015:14:35:41 +0800] "GET / HTTP/1.1" 200 1468 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
1.85.49.230 - - [07/Apr/2015:15:01:14 +0800] "GET / HTTP/1.1" 200 1468 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0"
1.85.49.230 - - [07/Apr/2015:15:01:14 +0800] "GET /cacti/images/auth_login.gif HTTP/1.1" 200 21265 "http://125.76.228.16:2002/" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0

 

192.168.1.88 - fgy1 [26/Nov/2015:08:42:35 +0800] "PROPFIND /webdav/Thumbs.db HTTP/1.1" 404 291 "-" "Microsoft-WebDAV-MiniRedir/6.1.7601"
192.168.1.88 - fgy1 [26/Nov/2015:08:42:37 +0800] "GET /webdav/er.txt HTTP/1.1" 200 5 "-" "Microsoft-WebDAV-MiniRedir/6.1.7601"
192.168.1.88 - fgy1 [26/Nov/2015:08:43:14 +0800] "PROPFIND /webdav HTTP/1.1" 301 311 "-" "Microsoft-WebDAV-MiniRedir/6.1.7601"
192.168.1.88 - - [26/Nov/2015:08:43:14 +0800] "PROPFIND /webdav/ HTTP/1.1" 401 478 "-" "Microsoft-WebDAV-MiniRedir/6.1.7601"
192.168.1.88 - fgy1 [26/Nov/2015:08:43:14 +0800] "PROPFIND /webdav/ HTTP/1.1" 207 842 "-" "Microsoft-WebDAV-MiniRedir/6.1.7601"



该问题得到解决了,一定得分清楚Apache的几种标签:<Directory>,<Files>,<Location>,分别是目录,文件,网络空间。如果用了代理就得用<Location>。
我的Apache+Tomcat 集群,用到了代理模式,最近一直有PROPFIND的大量请求,而且IP不固定,所以想禁掉该类请求方式,故我的配置如下:
<Location />
<Limit PROPFIND>
Order allow,deny
Deny from all
</Limit>
</Location> 

 

含义精解(服务的停止与重启)

####发送TERM或者stop信号
Sending the TERM or stop signal to the parent causes it to immediately attempt to kill off all of its children. It may take it several seconds to complete killing off its children. Then the parent itself exits. Any requests in progress are terminated, and no further requests are served.

kill -TERM `cat /var/run/httpd/httpd.pid`或者apachectl -k stop


####发送HUP或者restart信号
Sending the HUP or restart signal to the parent causes it to kill off its children like in TERM, but the parent doesn't exit. It re-reads its configuration files, and re-opens any log files. Then it spawns a new set of children and continues serving hits.
发送hup或者restart信号给父进程会引起它杀死所有的子进程(就像term信号一样),但父进程不退出。它重读配置文件,并且重新打开日志文件。然后派生一组新的子进程并继续服务。

09:58:58 49 /var/run/httpd:#cat httpd.pid 14688 09:59:02 50 /var/run/httpd:#ps -ef|grep http root 14688 1 0 09:54 ? 00:00:00 /usr/sbin/httpd -k start apache 14689 14688 0 09:54 ? 00:00:00 /usr/sbin/httpd -k start apache 14690 14688 0 09:54 ? 00:00:00 /usr/sbin/httpd -k start apache 14691 14688 0 09:54 ? 00:00:00 /usr/sbin/httpd -k start apache 14692 14688 0 09:54 ? 00:00:00 /usr/sbin/httpd -k start root 14777 13050 0 09:59 pts/0 00:00:00 grep http 09:59:07 51 /var/run/httpd:#kill -HUP `cat httpd.pid`或者apachectl -k restart
####父进程pid号未变验证了父进程不退出 09:59:35 52 /var/run/httpd:#ps -ef|grep http root 14688 1 0 09:54 ? 00:00:00 /usr/sbin/httpd -k start apache 14795 14688 0 09:59 ? 00:00:00 /usr/sbin/httpd -k start apache 14796 14688 0 09:59 ? 00:00:00 /usr/sbin/httpd -k start apache 14797 14688 0 09:59 ? 00:00:00 /usr/sbin/httpd -k start apache 14798 14688 0 09:59 ? 00:00:00 /usr/sbin/httpd -k start root 14800 13050 0 09:59 pts/0 00:00:00 grep http 09:59:57 54 /var/run/httpd:#cat httpd.pid 14688

####发送USR1或者graceful信号
The USR1 or graceful signal causes the parent process to advise the children to exit after their current request (or to exit immediately if they're not serving anything).

10:21:43 64 /var/run/httpd:#kill -USR1 `cat httpd.pid`或者apachectl -k graceful
####从日志中可以看出是发出什么信号的
10:22:01 66 /var/run/httpd:#tail -f /var/log/httpd/error_log
[Sun Sep 06 10:12:04 2015] [notice] SIGHUP received.  Attempting to restart
[Sun Sep 06 10:12:04 2015] [notice] Digest: generating secret for digest authentication ...
[Sun Sep 06 10:12:04 2015] [notice] Digest: done
[Sun Sep 06 10:12:04 2015] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 configured -- resuming normal operations

[Sun Sep 06 10:21:59 2015] [notice] Graceful restart requested, doing restart
[Sun Sep 06 10:21:59 2015] [notice] Digest: generating secret for digest authentication ...
[Sun Sep 06 10:21:59 2015] [notice] Digest: done
[Sun Sep 06 10:21:59 2015] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 configured -- resuming normal operations

 

错误排障

11:57:05 111 /var/www/html/doc/mrtg2:#service httpd reload
Reloading httpd:                                           [FAILED]
11:57:07 112 /var/www/html/doc/mrtg2:#service httpd status
httpd dead but pid file exists
11:57:15 113 /var/www/html/doc/mrtg2:#rm -rf /var/run/httpd/httpd.pid
11:57:29 114 /var/www/html/doc/mrtg2:#service httpd start
Starting httpd:                                            [FAILED]
11:57:34 115 /var/www/html/doc/mrtg2:#service httpd status
httpd dead but subsys locked
12:00:16 121 /var/www/html/doc/mrtg2:#rm -rf /var/lock/subsys/httpd
12:00:44 122 /var/www/html/doc/mrtg2:#service httpd start
Starting httpd:                                            [  OK  ]

查看错误日志解决以上问题
12:08:57 130 /var/www/html/doc/mrtg2:#less /var/log/httpd/error_log
[Fri Apr 24 11:55:24 2015] [notice] SIGHUP received.  Attempting to restart
unable to start piped log program '/usr/local/apache/bin/rotatelogs /var/log/access_log 86400': No such file or directory
Unable to open logs
unable to start piped log program '/usr/local/apache/bin/rotatelogs /var/log/access_log 86400': No such file or directory
Unable to open logs

semaphore是一个内部用于与其子进程进行交流的工具," No space left on device: Couldn't create accept lock "的意思是说apache不能再创建新的semaphore进程。 用如下命令查看有多少 semaphore在运行。 #ipcs -s 你将会看到 ------ Semaphore Arrays -------- key semid owner perms nsems 0x00000000 68681743 apache 600 1 0x00000000 68714515 apache 600 1 0x00000000 68747291 apache 600 1 你可运行如下命令来安全的杀死每个 Semaphore(信号量) #ipcrm -s <semid> <semid>是上面ipcs -s输出的第二列值。 想要一次性将所有的Semaphore全部杀死,请运行如下命令: for semid in `ipcs -s |awk '{print $2}'`; do ipcrm -s $semid; done 如果不能再创建更多的Semaphores: 有些时候你可能想改变系统允许创建 semaphores的数量。这就需要改变内核参数。 运行以下命令来查看当前参数: #ipcs -l 修改 /etc/sysctl.conf文件,增加如下两行: kernel.msgmni = 1024 kernel.sem = 250 256000 32 1024 运行命令# sysctl -p 使刚改的参数生效。 (kernel.msgmni 该文件指定消息队列标识的最大数目,即系统范围内最大多少个消息队列。缺省设置 :16) 关于/var/lock/subsys目录 总的来说,系统关闭的过程(发出关闭信号,调用服务自身的进程)中会检查/var/lock/subsys下的文件,逐一关闭每个服务,如果某一运行的服务在/var/lock/subsys下没有相应的选项。在 系统关闭的时候,会像杀死普通进程一样杀死这个服务。通过察看/etc/rc.d/init.d下的脚本,可以发现每个服务自己操纵时都会去查看/var/lock/subsys下相应的服务。

 

This is the status code that the server sends back to the client. This information is very valuable, because it reveals whether the request resulted in a successful response (codes beginning in 2), a redirection (codes beginning in 3), an error caused by the client (codes beginning in 4), or an error in the server (codes beginning in 5). The full list of possible status codes can be found in the HTTP specification (RFC2616 section 10).

这是服务器返回给客户端的状态代码。这个信息非常有价值,因为它显示请求是否以一个成功应答(代码以2开头),一个重定向(代码以3开头),一个由客户端引起的错误(代码以4开头),或者一个服务端的错误(代码以5开头)为结果。一份可能的状态代码的完全列表能在HTTP规范中被发现。

      Status-Code    =
            "100"  ; Section 10.1.1: Continue
          | "101"  ; Section 10.1.2: Switching Protocols
          | "200"  ; Section 10.2.1: OK
          | "201"  ; Section 10.2.2: Created
          | "202"  ; Section 10.2.3: Accepted
          | "203"  ; Section 10.2.4: Non-Authoritative Information
          | "204"  ; Section 10.2.5: No Content
          | "205"  ; Section 10.2.6: Reset Content
          | "206"  ; Section 10.2.7: Partial Content
          | "300"  ; Section 10.3.1: Multiple Choices
          | "301"  ; Section 10.3.2: Moved Permanently
          | "302"  ; Section 10.3.3: Found
          | "303"  ; Section 10.3.4: See Other
          | "304"  ; Section 10.3.5: Not Modified
          | "305"  ; Section 10.3.6: Use Proxy
          | "307"  ; Section 10.3.8: Temporary Redirect
          | "400"  ; Section 10.4.1: Bad Request
          | "401"  ; Section 10.4.2: Unauthorized
          | "402"  ; Section 10.4.3: Payment Required
          | "403"  ; Section 10.4.4: Forbidden
          | "404"  ; Section 10.4.5: Not Found
          | "405"  ; Section 10.4.6: Method Not Allowed
          | "406"  ; Section 10.4.7: Not Acceptable
          | "407"  ; Section 10.4.8: Proxy Authentication Required
          | "408"  ; Section 10.4.9: Request Time-out
          | "409"  ; Section 10.4.10: Conflict
          | "410"  ; Section 10.4.11: Gone
          | "411"  ; Section 10.4.12: Length Required
          | "412"  ; Section 10.4.13: Precondition Failed
          | "413"  ; Section 10.4.14: Request Entity Too Large
          | "414"  ; Section 10.4.15: Request-URI Too Large
          | "415"  ; Section 10.4.16: Unsupported Media Type
          | "416"  ; Section 10.4.17: Requested range not satisfiable
          | "417"  ; Section 10.4.18: Expectation Failed
          | "500"  ; Section 10.5.1: Internal Server Error
          | "501"  ; Section 10.5.2: Not Implemented
          | "502"  ; Section 10.5.3: Bad Gateway
          | "503"  ; Section 10.5.4: Service Unavailable
          | "504"  ; Section 10.5.5: Gateway Time-out
          | "505"  ; Section 10.5.6: HTTP Version not supported
          | extension-code

      extension-code = 3DIGIT
      Reason-Phrase  = *<TEXT, excluding CR, LF>

 

需求:指定的ip访问status与info,非法ip在日志中留有记录

三步走就可以用这个地址访问了server-info与server-status的配置是一样的  http://172.16.1.44/server-status  http://172.16.1.44/server-info

改配置
1.开模块,
2.去注释,并允许要允许的主机。顺序为先拒绝后允许,拒绝所有,再允许个别。ExtendedStatus On只是为了在server-status中显示更多信息罢了
3.重启服务器生效
vi httpd.conf  修改三个地方
1.LoadModule status_module modules/mod_status.so
2.ExtendedStatus On
3.
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 172.16.1.254
</Location>
4.service httpd reload

看日志
access_log
192.168.1.90 - - [24/Apr/2015:09:58:12 +0800] "GET /server-info HTTP/1.1" 403 290 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0"
error_log
[Fri Apr 24 09:58:12 2015] [error] [client 192.168.1.90] client denied by server configuration: /var/www/html/server-info

 

需求:查看文件列表形式

注释掉这一行,就可以看到文件的列表形式
#Include conf.d/*.conf

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

 

需求:轮替日志

CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/access_log 86400" common

上面这个可能不能正常使用,所以用下面的那一条,在httpd.conf中加入下面的一条指令,然后访问页面,日志就会在定义的时间内替换。

CustomLog "||/usr/sbin/rotatelogs /var/log/httpd/access_log 86400" common

[root@84-monitor httpd]# vi /etc/httpd/conf/httpd.conf
[root@84-monitor httpd]# service httpd reload
Starting httpd:                                            [  OK  ]

定义时间内没有访问,不会轮替。有访问,86400这个时间一到就轮替。

[root@84-monitor httpd]# ll
total 104
-rw-r--r--. 1 root root  1001 Apr  3 17:46 access_log
-rw-r--r--. 1 root root   950 Apr  3 18:00 access_log.1428055200
-rw-r--r--. 1 root root   950 Apr  3 18:01 access_log.1428055260
-rw-r--r--. 1 root root  2850 Apr  3 18:02 access_log.1428055320
-rw-r--r--. 1 root root   475 Apr  3 18:03 access_log.1428055380

 

cgi脚本  bash,perl,python,php,等

cgi脚本时,两种类型的报错
[Wed May 06 15:23:29 2015] [error] [client 192.168.1.88] (8)Exec format error: exec of '/var/www/cgi-bin/a' failed
[Wed May 06 15:23:29 2015] [error] [client 192.168.1.88] Premature end of script headers: a

[Wed May 06 15:41:08 2015] [error] [client 192.168.1.88] malformed header from script. Bad header=a.sh: a.sh


LoadModule cgi_module modules/mod_cgi.so
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
确保以上两条指令开启

bash脚本
1
.修改cgi-bin目录的权限,然后在此目录下新建脚本文件 2.内容如下 vi b #! /bin/bash echo Content-type: text/html echo "" ifconfig 注意到上面的输出的第一行必须是输出“Content-type: text/html“否则Apache识别不了这个文本页面的输出。 3.浏览器访问 http://172.16.1.44/cgi-bin/b

python脚本
16:33:45 141 /var/www/cgi-bin:#vi a
#! /usr/bin/python
print("Content-type: text/html\n")
print(5*5)

#! /usr/bin/python
print("Content-type: text/html\n")
a=['spam','eggs',30,50]
print(a[2])



php脚本

 

http://www.ietf.org/rfc/rfc3875  cgi/1.1

CGI是一种接口的标准,并不区分编程语言,也就是说,CGI可以用任何一种语言编写,只要这种语言具有标准输入、输出和环境变量。CGI会将标准输出重定向到给http的response,返回给浏览器。
CGI严格的介绍,公共网关接口CGI(Common GatewayInterface) 是WWW技术中最重要的技术之一,有着不可替代的重要地位。CGI是外部应用程序(CGI程序)与Web服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的规程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI将Web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。

CGI的输出结果需要是HTML形式或浏览器能显示的形式,否则其结果不会在浏览器中显示。 另外在CGI程序的所有输出前面必须有一个MIME类型的头,即HTTP头,对浏览器指明所接收内容的类型,大多数情况下,形如: Content
-type: text/html 网络访问CGI程序,浏览器中可能会发生四种情况: CGI程序的输出 太好了!这说明一切正常。 CGI程序的源代码或者一个"POST Method Not Allowed"消息 这说明Apache没有被正确配置以执行CGI程序,重新阅读配置Apache看看遗漏了什么。 一个以"Forbidden"开头的消息 这说明有权限问题。参考Apache error log和下面的文件的权限。 一个"Internal Server Error"消息 查阅Apache error log,可以找到CGI程序产生的出错消息"Premature end of script headers"。对此,需要检查下列各项,以找出不能产生正确HTTP头的原因。 文件的权限 记住,服务器不是以你的用户身份运行的,就是说,在服务器启动后,拥有的是一个非特权用户的权限-通常是``nobody''或者``www'' -而需要更大的权限以允许文件的执行。通常,给予``nobody''足够的权限以执行文件的方法是,对文件赋予everyone execute权限: chmod a+x first.pl 另外,如果需要对其他文件进行读取或写入,也必须对这些文件赋予正确的权限。 如果服务器被配置为使用su exec则是一个例外。这个程序允许CGI程序根据其所在虚拟主机或用户宿主目录的不同而以不同的用户权限运行。Su exec有极其严格的权限校验,任何校验失败都会使CGI程序运行失败而产生"Internal Server Error"。对此,需要检查su exec的日志文件以发现哪个安全校验出问题了。 路径信息 当你在命令行执行一个程序,某些信息会自动传给shell而无须你操心,比如一个路径,告诉shell你所引用的文件可以在哪儿找到。 但是,在CGI程序通过网站服务器执行时,则没有此路径,所以,你在CGI程序中引用的任何程序(如sendmail)都必须指定其完整的路径,使shell能找到它们以执行你的CGI程序。 一种普通的用法是,在CGI程序的第一行中指明解释器(通常是perl),形如: #!/usr/bin/perl 必须保证它的确指向解释器。 语法错误 多数CGI程序失败的原因在于程序本身有问题,尤其是在已经消除上述两种错误而CGI挂起的情况下。在用浏览器测试以前,先在命令行中执行你的程序,能够发现大多数的问题。 出错记录 出错记录是你的朋友。任何错误都会在出错记录中有记载,所以你应该首先查看它。如果你的网站空间提供者不允许访问出错记录,那么你应该考虑换一个空间提供者。学会阅读出错记录,可以快速找出问题并快速解决。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值