基于linux下的apache服务

http服务 

首先创造一个纯净的环境

一、http服务基本内容

[root@dns-server mysqladmin]# rpm -e httpd php php-mysql
[root@dns-server mysqladmin]# rm -fr /var/www

   77  yum install httpd -y       安装服务软件

   78  systemctl start httpd      启动服务

       systemctl stop firewalld          关闭防火墙

       systemctl   disable   firewalld

   81  netstat -antlupe | grep httpd        查看服务端口
   82  cd /var/www/html           (默认发布目录) 

   84  vim index.html           (默认发布文件

             hello world


更改服务端口

96  vim /etc/httpd/conf/httpd.conf     (主配置文件)

                   42 Listen 8080   (更改服务端口
   97  systemctl restart httpd

访问172.25.254.113:8080


        mkdir  /westos/html    -p
        cd /westos/html

        vim index.html 

                 xdxd

 更改默认发布目录

102  vim /etc/httpd/conf/httpd.conf

           109#DocumentRoot "/var/www/html"
                  DocumentRoot "/westos/html"   (更改默认发布目录
               <Directory "/westos">
                    Require all granted   
              </Directory>

 103  systemctl restart httpd


        cd   /westos/html

         vim   test.html

                test.html

  更改默认发布目录,更改默认发布文件

108  vim /etc/httpd/conf/httpd.conf

      109#DocumentRoot "/var/www/html"
             DocumentRoot "/westos/html"   (更改默认发布目录)
        <Directory "/westos">
             Require all granted
             DirectoryIndex test.html       (更改默认发布文件)

        </Directory>

109  systemctl restart httpd


 
  114  mkdir linux
  115  ls
  116  cd linux
  117  ls

  118  vim index.html

          linux.test.html

  119  vim /etc/httpd/conf/httpd.conf               编辑主配置文件
        #DocumentRoot "/var/www/html"
        DocumentRoot "/westos/html"                默认目录为/westos/html
       <Directory "/westos/html/linux">
         DirectoryIndex index.html                      默认文件为index.html
       </Directory>
      <Directory "/westos">               
        Require all granted
       DirectoryIndex test.html                           目录为/wetos/html/westos发布文件为test.html
      </Directory>

  120  systemctl restart httpd



  140  systemctl stop firewalld 

141  vim /etc/httpd/conf/httpd.conf   


142  systemctl restart httpd

143  cd /var/www/html 

144  ls 

145  mkdir westos 

146  ls

  147  cd westos

  148  vim index.html

          westos'spage

  149  vim /etc/httpd/conf/httpd.conf


  此时无论是谁都可以访问,我们可以设置允许和不允许哪格ip访问

150  systemctl restart httpd

  151  vim /etc/httpd/conf/httpd.conf               编辑主配置文件

       119 DocumentRoot "/var/www/html"
     120 #DocumentRoot "/westos/html"
    121
   122<Directory "/var/www/html/westos">
   123 Order Deny,Allow
    124     Allow from 172.25.254.55                   只允许172.25.254.55访问
   125    Deny  from All

   126</Directory>


  152  systemctl restart httpd


  153  vim /etc/httpd/conf/httpd.conf

            DocumentRoot "/var/www/html"
     120 #DocumentRoot "/westos/html"
    121
   122<Directory "/var/www/html/westos">
   123 Order Allow,Deny
    124     Allow from All                      只不允许172.25.254.55访问
   125    Deny  from 172.25.254.55

   126</Directory>


  154  systemctl restart httpd



vim /etc/httpd/conf/httpd.conf            (将前面做的实验还原)

    119 DocumentRoot "/var/www/html"
     120 #DocumentRoot "/westos/html"
    121
   122 #<Directory "/var/www/html/westos">
   123  #   Order Deny,Allow
    124   #   Allow from 172.25.254.13
   125    #  Deny  from All

   126 #</Directory>


systemctl restart httpd

设置那个用户可以访问那个不可以访问

  155  cd /etc/httpd/
  156  ls
  157  htpasswd -cm apacheuser admin               添加用户admin
  158  htpasswd -m apacheuser tom
  159  cat apacheuser                                          查看用户

  160  vim /etc/httpd/conf/httpd.conf

               <Directory "/var/www/html/westos">
    129     AuthUserFile  /etc/httpd/apacheuser
    130     AuthName  "Please input user and password !!"
   131     AuthType  basic
              Require  user admin                              只允许admin用户用密码访问,而其他用户不可以访问
   134 </Directory>


 


161  systemctl restart httpd

  162  vim /etc/httpd/conf/httpd.conf

      128 <Directory "/var/www/html/westos">
    129     AuthUserFile  /etc/httpd/apacheuser
    130     AuthName  "Please input user and password !!"
   131     AuthType  basic
    132 #    Require  user admin
   133      Require  valid-user                      此时所有的用户都可以登陆访问
   134 </Directory>
   135






将前面作的实验还原


        

为了使我们每打开一个网址所显示内容不同,我们做了如下实验

虚拟机

  167  pwd
  /etc/httpd
  168  ls
  169  cd conf.d
  170  ls
  171  vim default.conf                      编辑/etc/httpd/default.conf文件
      <VirtualHost _default_:80>
        DocumentRoot  /var/www/html
        CustomLog "logs/default.log" combined

       </VirtualHost>



  172  mkdir /var/www/virtual/westos.com/news  -p          建立目录
  173  mkdir /var/www/virtual/westos.com/music  -p
  174  vim /var/www/virtual/westos.com/music/index.html             编写默认发布文件内容
       music
  175  vim /var/www/virtual/westos.com/news/index.html              编写默认发布文件内容
       news
  176  vim news.conf
      <VirtualHost *:80>
            ServerName news.westos.com
           DocumentRoot "/var/www/virtual/westos.com/news/"
           CustomLog "logs/news.log" combined
     </VirtualHost>
     <Directory "/var/www/virtual/westos.com/news/">
         Require all granted

     </Directory>


  178  cp news.conf  music.conf
  179  vim music.conf
       <VirtualHost *:80>
            ServerName music.westos.com
            DocumentRoot "/var/www/virtual/westos.com/music/"
            CustomLog "logs/music.log" combined
     </VirtualHost>
     <Directory "/var/www/virtual/westos.com/music/">
            Require all granted

     </Directory>



  180  systemctl restart httpd
 
浏览器查找的机子真机
   vim /etc/hosts
   172.25.254.155  www.westos.com  news.westos.com  music.westos.com



生成证书
  197  yum install mod_ssl -y
  198  ls /etc/httpd/conf.d
  199  yum install crypto-utils -y

  200  genkey www.westos.com


  201  vim /etc/httpd/conf.d/ssl.conf
      101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt          
 
        103 #   Server Private Key:
       104 #   If the key is not combined with the certificate, use this
        105 #   directive to point at the key file.  Keep in mind that if
        106 #   you've both a RSA and a DSA private key you can configure
        107 #   both in parallel (to also allow the use of DSA ciphers, etc.)
         108 #SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
        109 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key



  202  systemctl restart httpd





加密(给网址加密)
  139  cd /etc/httpd/conf.d
  140  ls
  141  cp news.conf login.conf

  142  vim login.conf


  143  mkdir -p /var/www/virtual/westos.com/login/

  145  vim /var/www/virtual/westos.com/login/index.html

        login's page

  146  systemctl restart httpd


 

yum install  httpd-manual    httpd手册
   
***.php(安装php)   *****.cgi(修改配置文件)
  168  cd /var/www/html
  169  ls
  170  vim index.php
       <?php
       phpinfo();
       ?>
  171  vim /etc/httpd/conf/httpd.conf
       176 #
       177 <IfModule dir_module>
       178     DirectoryIndex index.php  index.html
       179 </IfModule>

  172  systemctl restart httpd

浏览器     172.25.254.155


  173  yum install php -y
  174  systemctl restart httpd
  177  mkdir cgi
  178  ls
  179  vim cgi/index.cgi
    #!/usr/bin/perl
     print "Content-type: text/html\n\n";
      print `date`;
  180  chmod +x cgi/index.cgi
  181  ./cgi/index.cgi
  182  cd /etc/httpd/conf.d
  183  ls
  184  vim default.conf
      <VirtualHost _default_:80>
           DocumentRoot  /var/www/html
            CustomLog "logs/default.log" combined
      </VirtualHost>
      <Directory "/var/www/html/cgi">
        Options +ExecCGI
        AddHandler cgi-script .cgi
        DirectoryIndex index.cgi
     </Directory>

  185  systemctl restart httpd
浏览器  172.25.254.155/cgi/index.cgi



论坛搭建
cd /var/www/html
  203  ls
  204  lftp 172.25.254.250
  205  clear
  206  ls
  207  unzip Discuz_X3.2_SC_UTF8.zip
  208  clear
  209  ls
  210  chmod 777 /var/www/html/upload/ -R
  212  yum install php-mysql.x86_64
  213  systemctl start mariadb
  214  systemctl restart httpd




真机可以上网,虚拟机不能上网,让虚拟机也可以上网
真机配置

  218  cd /etc/sysconfig/network-scripts/
     GATEWAY=172.25.254.250
     DNS1=114.114.114.114
  219  ls
  220  vim ifcfg-eth0
  221  systemctl restart  network

  222  ping www.baidu.com


  223  yum install squid -y
  224  vim /etc/squid/squid.conf
       http_access allow all
    57
    58 # Squid normally listens to port 3128
    59 http_port 3128
    60
    61 # Uncomment and adjust the following to add a disk cache directory.
    62 cache_dir ufs /var/spool/squid 100 16 256
    63

  225  systemctl start squid

一个提供http服务一个提供squid服务,提高效率

把上个实验做在真机里做的还原不再依靠172.25.254.55
一个提供httpd服务一个提供squid(这个上面没有httpd服务)
httpd服务:(172.25.254.155)
systemctl restart httpd

squid服务:(172.25.254.213)
   17  rpm -qa | grep httpd
   18  yum remove httpd
   22  rpm -qa | grep httpd
   23  yum install squid -y
   24  systemctl start  squid
   25  vim /etc/squid/squid.conf
      # And finally deny all other access to this proxy
       http_access allow all

      # Squid normally listens to port 3128
      http_port 80 vhost vport
      cache_peer 172.25.254.155 parent 80 0 proxy-only

      # Uncomment and adjust the following to add a disk cache directory.
     cache_dir ufs /var/spool/squid 100 16 256

      # Leave coredumps in the first cache dir
       coredump_dir /var/spool/squid

   26  systemctl restart squid.service
   27  systemctl stop firewalld


浏览器:此时 172.25.254.213 可以看到与172.25.254.155同样的内容.


  

猜你喜欢

转载自blog.csdn.net/xdmaidou/article/details/80516699
今日推荐