码迷,mamicode.com
首页 > Web开发 > 详细

linux-apache

时间:2017-11-21 10:45:02      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:linux之http


1.   ######## apache#######


企业中常用的web服务,用来提供http://(超文本传输协议)


技术分享图片

2.apache的安装部署######

[root@liu yum.repos.d]# yum install httpd-y  安装httpd

[root@liu yum.repos.d]# rpm -qc httpd       查看httpd服务的配

[root@liu ~]# yum install httpd-manual-y  安装http手册

 技术分享图片

[root@liu yum.repos.d]# systemctl starthttpd  开启httpd服务

[root@liu yum.repos.d]# systemctl enablehttpd 设定http开机开启

[root@liu yum.repos.d]# systemctl stopfirewalld     关闭防火墙

[root@liu yum.repos.d]# systemctl disablefirewalld  设定开机关闭火墙


测试

            http://172.25.12.12

可在浏览器输入:http://172.25.12.12/manual    查看手册

[root@liu ~]# cd /etc/httpd/conf.d

[root@liu conf.d]# ls

autoindex.conf  manual.conf README  userdir.conf  welcome.conf

3.apche基础信息

主配置目录:             /etc/httpd/conf技术分享图片

[root@liu conf.d]# vim/etc/httpd/conf/httpd.conf   编辑主配置文件

 

39 # prevent Apache from glomming onto allbound IP addresses.

 40 #

 41#Listen 12.34.56.78:80

 42Listen 80     默认端口为80  可在此处修改端口

 技术分享图片

[root@liu conf.d]# systemctl restarthttpd   重启服务

技术分享图片


主配置文件:             /etc/httpd/conf/httpd.conf

子配置目录:             /etc/httpd/conf.d/

子配置文件:              /etc/httpd/conf.d/*.conf

默认发布目录:            /var/www/html

默认发布文件:            index.html

默认端口:                80

默认安全上下文:           http_sys_content_t

程序开启默认用户:         apache

apache日志:             /etc/httpd/logs/*

 

报错时可查看日志

            > /var/log/messsages

            cat /var/log/messages

            cat /etc/httpd/logs/error_log



[root@liu conf.d]# cd /var/www/html

[root@liu html]# ls

[root@liu html]#

[root@liu html]# vim index.html  

 技术分享图片

1 <h1>你好!!!</h1>

 

163 <IfModule dir_module>

164    DirectoryIndex index.html   默认发布顺序  不存在时访问下一个

165 </IfModule>

 技术分享图片

技术分享图片

[root@liu html]# vim test.html

 

1 <h1>我很好!!!</h1>

 技术分享图片

[root@liu html]# ls

index.html test.html

 

163 <IfModule dir_module>

164    DirectoryIndex test.html index.html

165 </IfModule>

 技术分享图片

修改默认发布目录

[root@liu html]# pwd

/var/www/html

 

[root@liu html]# mkdir -p /www/html     新创建目录

[root@liu html]# vim /www/html/index.html 编辑文件

1 <h1> /www/html‘s page </h1>

 技术分享图片

118 #

119 DocumentRoot"/var/www/html"   默认发布目录

120

119 #DocumentRoot"/var/www/html"  修改默认发布目录

技术分享图片

120 DocumentRoot "/www/html"

121 <Directory "/www">

122      Require all granted   授权

123 </Directory>

 技术分享图片

[root@liu html]# ls -l /www/html

total 4

-rw-r--r--. 1 root root 28 Nov 18 21:30index.html

 

[root@liu html]# getenforce   查看selinux状态

Enforcing

 技术分享图片


[root@liu conf.d]# ls -Z /var/www/

drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin

drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 html


[root@liu html]# semanage fcontext -a -t httpd_sys_content_t ‘/www(/.*)?‘ 更改安全上下文

[root@liu html]# restorecon -RvvF /www/


[root@liu html]# ls -Z /www/    查看安全上下文

drwxr-xr-x. root rootsystem_u:object_r:httpd_sys_content_t:s0 html

技术分享图片


为了接下来实验方便  把修改的东西改回来!!!

4####### apache 的虚拟主机

 

[root@liu html]# mkdir/var/www/virtual/linux.westos.com/html -p

[root@liu html]# mkdir/var/www/virtual/c.westos.com/html -p

[root@liu html]#  vim/var/www/virtual/linux.westos.com/html/index.html

 

1 <h1>www.westos.com</h1>技术分享图片

 

[root@liu html]# vim /var/www/virtual/c.westos.com/html/index.html

 

1 <h1>c.westos.com</h1>

 技术分享图片

 

[root@liu html]# pwd

/var/www/html

 技术分享图片

[root@liu html]# cd /etc/httpd/conf.d/   切换到子配置目录

[root@liu conf.d]# ls

autoindex.conf  manual.conf README  userdir.conf  welcome.conf

 

[root@liu conf.d]# vim default.conf

 

1 <VirtualHost _default_:80>

 2           DocumentRoot"/var/www/html"

 3           CustomLog"logs/www.westos.com.logs" combined

  4</VirtualHost>

 技术分享图片

[root@liu conf.d]# vim linux.conf

 

 <VirtualHost *:80>

 2           ServerNamelinux.westos.com   指定站点名称

 3           DocumentRoot"/var/www/virtual/linux.westos.com/html" 站点默认发布目录

 4           CustomLog"logs/linux.westos.com.logs" combined   站点日志combiend标志四种日至的集合

  5</VirtualHost>

  6<Directory "/var/www/virtual/linux.westos.com/html">

 7           Require all granted

  8</Directory>

 技术分享图片

[root@liu conf.d]# vim c.conf

 

1 <VirtualHost *:80>

 2           ServerNamec.westos.com

 3           DocumentRoot"/var/www/virtual/c.westos.com/html"

 4           CustomLog"logs/c.westos.com.logs" combiend

  5</VirtualHost>

  6<Directory "/var/www/virtual/c.westos.com/html">

 7           Require all granted

  8</Directory>

 

[root@liu conf.d]# systemctl restarthttpd  重启

 

[root@liu conf.d]# ls

autoindex.conf  default.conf manual.conf  userdir.conf

c.conf          linux.conf    README      welcome.conf


[root@liu conf.d]# mv default.confadefault.conf   重命名

 技术分享图片

 

本地做好解析

[root@liu conf.d]# vim /etc/hosts

 技术分享图片


 技术分享图片

 技术分享图片


技术分享图片


5.##### apche 内部的访问控####

针对与主机的访问控制

[root@liu conf.d]# mkdir /var/www/html/test

[root@liu conf.d]# vim/var/www/html/test/index.html

 

1 <h1>都会成为回忆!!!</h1>

~                                      

 技术分享图片

[root@liu conf.d]# vim adefault.conf

 6           Order allow,deny  列表读取顺序,后读取的列表会覆盖先读取内容的重复部分


 技术分享图片


[root@liu conf.d]# systemctl restart httpd

技术分享图片

12主机访问被拒绝

 技术分享图片

6. ####用户方式的访问控制####

[root@liu conf.d]# htpasswd -cm/etc/httpd/userpass admin  创建用户admin

 技术分享图片

 

[root@liu conf.d]# vim adefault.conf

 技术分享图片

 

[root@liu conf.d]# mkdir/var/www/html/admin

[root@liu conf.d]# vim /var/www/html/admin/index.html


 1<h1>admin‘s page</h1>

 技术分享图片

[root@liu conf.d]# systemctl restart httpd

 技术分享图片

 技术分享图片

[root@liu conf.d]# htpasswd -m/etc/httpd/userpass admin1   不能 -cm 不然前面的会覆盖

 技术分享图片

[root@liu conf.d]# vim adefault.conf

 技术分享图片

 

 技术分享图片

 技术分享图片

[root@liu conf.d]# cd /var/www/html

[root@liu html]# ls

admin index.html  test  test.html

[root@liu html]# vim index.php

 技术分享图片

[root@liu html]# yum install php -y       安装php

[root@liu html]# cd /etc/httpd/conf.d/

[root@liu conf.d]# ls

adefault.conf   c.conf     manual.conf  README        welcome.conf

autoindex.conf  linux.conf php.conf     userdir.conf

[root@liu conf.d]# systemctl restart httpd

[root@liu conf.d]# vim/etc/httpd/conf/httpd.conf

技术分享图片

[root@liu conf.d]# systemctl restart httpd

 技术分享图片

 

[root@liu conf.d]# cd /var/www/html/

[root@liu html]# ls

admin index.html  index.php  test test.html

[root@liu html]# mkdir cgi      新建目录cgi

[root@liu html]# cd cgi/

[root@liu cgi]# vim index.cgi

1 #!/usr/bin/perl

 技术分享图片

[root@liu cgi]# chmod +x index.cgi    给权限

 技术分享图片

[root@liu cgi]# ./index.cgi             执行下脚本确保无误

Content-type: text/html

 

Sat Nov 18 23:18:53 CST 2017

 

[root@liu cgi]# cd /var/www/html

[root@liu html]# ls

admin cgi  index.html  index.php test  test.html

 

[root@liu html]# cd /etc/httpd/conf.d/

 

[root@liu conf.d]# vim adefault.conf

 

技术分享图片

 

[root@liu conf.d]# systemctl restart httpd

 

[root@liu conf.d]# getenforce

Enforcing

[root@liu conf.d]# setenforce 0   调整selinux为警告态

 

[root@liu conf.d]# semanage fcontext -a -thttpd_sys_script_exec_t ‘/var/www/html/cgi(/.*)?‘                                 更改上下文

[root@liu conf.d]# restorecon -RvvF/var/www/html/cgi

 技术分享图片

[root@liu conf.d]# ss -antluep | grep 443

[root@liu conf.d]# yum install mod_ssl -y     安装

[root@liu conf.d]# systemctl restart httpd

[root@liu conf.d]# yum install crypto-utils-y

[root@liu conf.d]# genkey www.westos.com


 技术分享图片


技术分享图片


技术分享图片


[root@liu html]# cd /etc/httpd/conf.d/

[root@liu conf.d]# ls

adefault.conf   c.conf     manual.conf  README    userdir.conf

autoindex.conf  linux.conf php.conf     ssl.conf  welcome.conf

 

[root@liu conf.d]# vim ssl.conf

 

 技术分享图片

[root@liu conf.d]# systemctl restart httpd


 技术分享图片


技术分享图片


技术分享图片


[root@liu ~]# mkdir -p/var/www/html/virtual/login.westos.com/html

[root@liu ~]# vim/var/www/html/virtual/login.westos.com/html/index.html


 <h1>login.westos.com‘s page</h1>


[root@liu ~]# vim/etc/httpd/conf.d/login.conf

 <VirtualHost *:443>

 2        ServerNamelogin.westos.com

 3        DocumentRoot/var/www/html/virtual/login.westos.com/html

 4        CustomLog"logs/login.logs" combined

 5        SSLEngine On

 6        SSLCertificateFile/etc/pki/tls/certs/www.westos.com.crt

 7        SSLCertificateKeyFile/etc/pki/tls/private/www.westos.com.key

  8</VirtualHost>

  9<Directory "/var/www/html/virtual/login.westos.com/html">

 10       Require all granted

 11</Directory>

 12<VirtualHost *:80>

 13       ServerName login.westos.com

 14       RewriteEngine On

 15       RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]

 16</VirtualHost>

 

[root@liu ~]# systemctl restart httpd

 

[root@liu html]# vim /etc/hosts

 

3 172.25.12.12 linux.westos.comc.westos.com westos.com www.westos.com login.westos.com

 

 技术分享图片







linux-apache

标签:linux之http

原文地址:http://13362895.blog.51cto.com/13352895/1983630

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!