渡人自渡 发表于 2018-11-22 10:22:51

Apache 服务器安装与基本配置

  当前系统版本
  # uname -a
  Linuxlocalhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013x86_64 x86_64 x86_64 GNU/Linux
  # cat /etc/redhat-release
  Red HatEnterprise Linux Server release 6.4 (Santiago)
  关闭防火墙
  # service iptables stop
  iptables:Flushing firewall rules:                        
  iptables:Setting chains to policy ACCEPT: filter         
  iptables:Unloading modules:                              
  启动时关闭防火墙
  # chkconfig iptables off
  创建目录,挂载,安装.
  # mkdir /mnt/cdrom
  # mount /dev/cdrom /mnt/cdrom/
  mount: block device /dev/sr0 is write-protected, mounting read-only
  # cd /mnt/cdrom/Packages/
  # ls httpd*
  测试

  

  在创建APACHE会自动创建一个新的账户
  # tail /etc/passwd
  operator:x:11:0:operator:/root:/sbin/nologin
  games:x:12:100:games:/usr/games:/sbin/nologin
  gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
  ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
  nobody:x:99:99:Nobody:/:/sbin/nologin
  vcsa:x:69:69:virtual console memoryowner:/dev:/sbin/nologin
  saslauth:x:499:76:"Saslauthduser":/var/empty/saslauth:/sbin/nologin
  postfix:x:89:89::/var/spool/postfix:/sbin/nologin
  sshd:x:74:74:Privilege-separatedSSH:/var/empty/sshd:/sbin/nologin
  apache:x:48:48:Apache:/var/www:/sbin/nologin
  Apache服务器安装与基本配置
  配置每个用户的WEB站点
  1.启用配置每个用户的WEB站点
  # vi/etc/httpd/conf/httpd.conf
  
  #
  #UserDir is disabled by default since it can confirm the presence
  #of a username on the system (depending on home directory
  #permissions).
  #
   UserDir disabled root
  #
  #To enable requests to /~user/ to serve the user's public_html
  #directory, remove the "UserDir disabled" line above, and uncomment
  #the following line instead:
  #
   UserDir public_html
  
  #
  # Control access to UserDirdirectories.The following is an example
  # for a site where these directories arerestricted to read-only.
  #
  
      AllowOverride FileInfo AuthConfig Limit
      Options MultiViews Indexes SymLinksIfOwnerMatchIncludesNoExec
     
        Order allow,deny
        Allow from all
     
     
        Order deny,allow
        Deny from all
     
  
  重启服务
  #service httpd restart
  Stopping httpd:                                          
  Starting httpd:                                          
  创建用户
  #useradd alice
  
  转换成ALICE用户
  [root@localhostconf]# su - alice
  创建目录,更改权限
  $ cd
  $mkdir public_html
  $ ll-d /home/alice/
  drwx------. 3 alice alice4096 Aug 21 04:27 /home/alice/
  $chmod 711 /home/alice/
  $ ll-d /home/alice/
  drwx--x--x. 3 alice alice4096 Aug 21 04:27 /home/alice/
  
  进入目录修改所创个人站点
  $ vi index.html
  内容为Alice's Web Site
  检测

  创建虚拟目录
  # mkdir/opt/bbs
  # ls-ld /opt/bbs
  drwxr-xr-x 2 root root 4096 Aug 21 05:31/opt/bbs
  创建测试页
  # echo'BBS test page' > /opt/bbs/index.html
  方法一:
  # ln -s/opt/bbs/ /var/www/html/bbs
  # ls -l/var/www/html/bbs
  lrwxrwxrwx 1 root root 9 Aug 21 05:33/var/www/html/bbs -> /opt/bbs/

  

  清除换方法
  # rm/var/www/html/bbs
  rm: remove symbolic link`/var/www/html/bbs'? y
  方法二:
  # vi/etc/httpd/conf/httpd.conf

  清除
  # rm-rf /opt/bbs/
  创建虚拟主机
  配置域名解析和站点文件

  # mkdir/opt/crm
  # echo'CRM test page' > /opt/crm/index.html
  # mkdir/opt/oa
  # echo'OA test page' > /opt/oa/index.html
  # cd/etc/httpd/
  #ls
  conf conf.dlogsmodules run
  #mkdir vhost-conf.d
  #echo "Include vhost-conf.d/*.conf" >> conf/httpd.conf
  #
  配置基于端口的虚拟主机
  #vi /etc/httpd/vhost-conf.d/vhost-ip.conf
  Listen8001
  Listen 8002
  
  DocumentRoot /opt/crm/
  
  
  DocumentRoot /opt/oa/
  
  #apachectl configtest
  Syntax OK
  #service httpd restart
  Stopping httpd:                                          
  Startinghttpd:                                          
  


  清除环境
  # rm-i /etc/httpd/vhost-conf.d/vhost-ip.conf
  rm: remove regular file`/etc/httpd/vhost-conf.d/vhost-ip.conf'? y
  #
  配置基于域名的虚拟机
  # vi/etc/httpd/vhost-conf.d/vhost-name.conf
  NameVirtualHost *:80
  
  ServerName crm.abc.local
  DocumentRoot /opt/crm/
  
  
  ServerName oa.abc.local
  DocumentRoot /opt/oa/
  
  #apachectl configtest
  Syntax OK
  #service httpd restart
  Stopping httpd:                                          
  Starting httpd:                                          
  


  

  




页: [1]
查看完整版本: Apache 服务器安装与基本配置