1.4笔记

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

安装apache2.4
[root@node1 ~]# yum install apr* pcre* -y     perl*
[root@node1 ~]# tar fx httpd-2.4.52.tar.gz
./configure \
--prefix=/usr/local/httpd \指定将 httpd 服务程序安装到哪个目录下如/usr/local/httpd
--enable-so \启用动态加载模块支持使 httpd 具备进一步扩展功能的能力。
--enable-rewrite \启用网页地址重写功能用于网站优化及目录迁移维护。
--enable-charset-lite \启动字符集支持以便支持使用各种字符集编码的网
--enable-cgi  \启用 CGI 脚本程序支持便于扩展网站的应用访问能力。

[root@node1 httpd-2.4.52]# make -j4 && make install
[root@node1 httpd]# /usr/local/httpd/bin/apachectl start
[root@node1 httpd]# curl http://localhost
[root@node1 httpd]# ln -s /usr/local/httpd/bin/* /usr/bin/

httpd.conf
ServerRoot "/usr/local/httpd" 软件根目录
Listen 80 监听端口
User daemon 启动者
Group daemon 启动组
ServerAdmin webmaster@benet.com 管理员邮箱
ServerName www.benet.com 服务名称
DocumentRoot "/usr/local/httpd/htdocs" 网页文件目录  index.html
DirectoryIndex index.html index.php 默认的页面文件名称
ErrorLog logs/error_log 错误日志
LogLevel warn 日志级别
CustomLog logs/access_log common 访问日志
PidFile logs/httpd.pid pid文件位置
CharsetDefault UTF-8 默认的字符编码
Include conf/extra/httpd-default.conf 包含文件

awstats
[root@node1 ~]# tar fx AWStats-AWSTATS_7_8.tar.gz 
[root@node1 ~]# mv AWStats-AWSTATS_7_8 /usr/local/awstats
[root@node1 ~]# cd /usr/local/awstats/tools/
[root@node1 tools]# ./awstats_configure.pl 
-----> Check for web server install

Enter full config file path of your Web server.
> /usr/local/httpd/conf/httpd.conf

-----> Check and complete web server config file '/usr/local/httpd/conf/httpd.conf'
Do you want me to setup Apache to write 'combined' log files [y/N] ? y

-----> Need to create a new config file ?
file (required if first install) [y/N] ? y

-----> Define config file name to create
> www.test.com

-----> Define config file path
> 直接回车

访问连接注意看提示
http://localhost/awstats/awstats.pl?config=www.test.com

[root@node1 tools]# vim /etc/awstats/awstats.www.test.com.conf 
LogFile="/usr/local/httpd/logs/access_log"
[root@node1 tools]# mkdir /var/lib/awstats
[root@node1 tools]# vim /usr/local/awstats/wwwroot/cgi-bin/lib/mime.pm 
在第59行后面添加逗号
[root@node1 tools]# ./awstats_updateall.pl now


[root@node1 tools]# vim /usr/local/httpd/conf/httpd.conf
<Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
    Require all granted
</Directory>
<IfModule !mpm_prefork_module>
        LoadModule cgid_module modules/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
        LoadModule cgi_module modules/mod_cgi.so
</IfModule>

[root@node1 tools]# apachectl restart


白名单
httpd.conf
<Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
    Require ip 192.168.1.5 网段  Require ip 192.168.1
</Directory>


黑名单
<Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
        <RequireAll>
        Require all granted
        Require not ip 192.168.1.4
        </RequireAll>
</Directory>


用户认证
[root@node1 httpd]# htpasswd -c /usr/local/httpd/conf/.awspwd test 创建用户密码


httpd.conf
<Directory "/usr /local/awstats/wwwroot">
    Options None
    AllowOverride None
        <RequireAll>
                Require all granted
                AuthName        "test tes test test"
                AuthType        Basic
                AuthUserFile    "/usr/local/httpd/conf/.awspwd"
                require valid-user
        </RequireAll>
</Directory>


虚拟主机
基于端口
基于IP
基于名称

基于IP

www.test.com = 192.168.1.3
www.hello.com=192.168.1.20
httpd.conf
<VirtualHost 192.168.1.3:80>
        DocumentRoot    "/usr/local/httpd/htdocs/test"
        ServerName      "www.test.com"
        ErrorLog        "logs/test.com-error.log"
        CustomLog       "logs/test.com-access.log" common
</VirtualHost>
<VirtualHost 192.168.1.20:80>
        DocumentRoot    "/usr/local/httpd/htdocs/hello"
        ServerName      "www.hello.com"
        ErrorLog        "logs/hello.com-error.log"
        CustomLog       "logs/hello.com-access.log" common
</VirtualHost>

###########额外的目录设置可能需要添加
<Directory "/opt"> #目录为自定义目录
        Require all granted
</Directory>

[root@node1 httpd]# cd /opt/
[root@node1 opt]# mkdir test hello
[root@node1 opt]# echo test > test/index.html
[root@node1 opt]# echo hello > hello/index.html

基于名字
www.test.com = 192.168.1.3
www.hello.com=192.168.1.3

#######NameVirtualHost######## 
<VirtualHost 192.168.1.3:80>
        DocumentRoot    "/usr/local/httpd/htdocs/test"
        ServerName      "www.test.com"
        ErrorLog        "logs/test.com-error.log"
        CustomLog       "logs/test.com-access.log" common
</VirtualHost>
<VirtualHost 192.168.1.3:80>
        DocumentRoot    "/usr/local/httpd/htdocs/hello"
        ServerName      "www.hello.com"
        ErrorLog        "logs/hello.com-error.log"
        CustomLog       "logs/hello.com-access.log" common
</VirtualHost>


[root@node1 opt]# vim /etc/hosts
192.168.1.3     www.test.com
192.168.1.3     www.hello.com

基于端口
Listen 80
Listen 8080

<VirtualHost 192.168.1.3:80>
        DocumentRoot    "/usr/local/httpd/htdocs/test"
        ServerName      "www.test.com"
        ErrorLog        "logs/test.com-error.log"
        CustomLog       "logs/test.com-access.log" common
</VirtualHost>
<VirtualHost 192.168.1.3:8080>
        DocumentRoot    "/usr/local/httpd/htdocs/hello"
        ServerName      "www.hello.com"
        ErrorLog        "logs/hello.com-error.log"
        CustomLog       "logs/hello.com-access.log" common
</VirtualHost>


nginx
[root@node1 ~]# tar fx nginx-1.6.0.tar.gz 
[root@node1 ~]# yum install pcre-devel zlib-devel -y
[root@node1 ~]# useradd -M -s /sbin/nologin nginx
[root@node1 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@node1 nginx-1.6.0]# make -j4 && make install
[root@node1 nginx]# ln -s /usr/local/nginx/sbin/* /usr/bin/


开启统计功能
[root@node1 nginx]# vim /usr/local/nginx/conf/nginx.conf
location /status        {
                stub_status     on;
                access_log      off;
        }

localhost/status

nginx虚拟主机
server {
        listen       80;
        server_name  www.test.com;
        charset utf-8;
        access_log  logs/test.access.log  main;
        location / {
            root   /opt/test;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  www.hello.com;
        charset utf-8; #字符编码
        access_log  logs/hello.access.log  main; #日志
        location / {
            root   /opt/hello;
            index  index.html index.htm;
        }
    }
将log_format&access_log子字段注释去掉

server字段中添加
allow x.x.x.x
deny all;

[root@node1 opt]# htpasswd -c /usr/local/nginx/conf/.testpwd test

nginx.conf
server {
        listen       80;
        server_name  www.test.com;
        auth_basic "test tes tes test"; #认证
        auth_basic_user_file /usr/local/nginx/conf/.testpwd;#认证
        charset utf-8;
        access_log  logs/test.access.log  main;
        location / {
            root   /opt/test;
            index  index.html index.htm;
        }
    }


安装tomcat
[root@node2 ~]# tar fx apache-tomcat-7.0.54.tar.gz 
[root@node2 ~]# cp -r apache-tomcat-7.0.54 /usr/local/tomcat
[root@node2 ~]# /usr/local/tomcat/bin/startup.sh 


生成页面文件
[root@node2 ~]# mkdir -p /var/www/html/test
[root@node2 ~]# vim /var/www/html/test/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
        <head>
        </head>
        <body>
                <% out.println("111111111111");%>
        </body>
</html>

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6