Apache Common parameters and examples
Example 1:apache Common parameters
[Email protected] chroot]# vim/etc/httpd/conf/httpd.conf #以下参数需要我们掌握
ServerRoot "/ETC/HTTPD" #apache配置文件的根目录
Timeout #超时时间
Listen #监听的端口
ServerAdmin [email protected] #设置管理员, e-mail address
ServerName 192.168.1.163:80 #服务器主机名.
DocumentRoot "/var/www/html" #网站页面根目录
Options Indexes followsymlinks #当一个目录没有默认首页时, allowing this directory list to be displayed
DirectoryIndex index.html index.html.var# Specify default home page
Example 2: Cancel the Apache default Welcome page:
[Email protected] ~]# vim/etc/httpd/conf.d/welcome.conf
#
# This configuration file enables the default "Welcome"
# page If there is no default index page present for
# The root URL. To disable the Welcome page, comment
# Out of all the lines below.
#
#<locationmatch "^/+$" > #把红色内容进行注释
# options-indexes
# ErrorDocument 403/error/noindex.html
#</locationmatch>
Create a home page file
[Email protected] ~]# echo "
Example 4: Modify the root directory and corresponding parameters, set access rights
Cases:
Set the document directory to/var/www/html/bbs
650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/06/0D/wKiom1mwxDOCXtROAAAVZnXSMyA075.png-wh_500x0-wm_ 3-wmp_4-s_307769781.png "title=" 1.png "alt=" Wkiom1mwxdocxtroaaavznxsmya075.png-wh_50 "/>
Directory and Access control:
<directory "/var/www/html/bbs" > #子目录会继承这个目录的属性
Options followsymlinks #Options: Indexes: Directory Browse #Followsymlinks: can be connected
AllowOverride None
Order Allow,deny
Allow from 192.168.1.0/24 #从哪里来的允许
Deny from 192.168.1.0/24 #从哪里来的拒绝
Allow from. baidu.com
#Allow, Deny is read, and if there is a conflict and is not stated, follow the one that follows the order option comma.
Who writes to the back, who has a high priority.
</Directory>
Example 5, using the alias feature, refers to a path other than the root directory of the Web site.
Add the/usr/local/phpmyadmin directory through the virtual directory feature to the Web site root directory. When you access http://192.168.1.63/phpmyadmin/, you can access the contents of the directory/usr/local/phpmyadmin.
Note: Apache aliases are also called virtual directories
Grammar:
Alias URL Path Physical path
Creating test catalogs and data
[Email protected] ~]# mkdir/usr/local/phpmyadmin
[Email protected] ~]# cp-r/boot/grub//usr/local/phpmyadmin/
[Email protected] ~]# echo "Test1" >/usr/local/phpmyadmin/a.html
Modifying a configuration file
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf
Alias/phpmyadmin "/usr/local/phpmyadmin/"
<directory "/usr/local/phpmyadmin/" >
Options Indexes multiviews FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
</Directory>
Note: alias/phpmyadmin/"/usr/local/phpmyadmin/" #/phpmyadmin/can be arbitrarily up. For example, change/phpmyadmin/to/php/then access the link: http://192.168.1.63/php/
Example 5, when there is no default home page in a directory, Access http://192.168.1.63/phpmyadmin/suppresses directory listing
To modify a configuration file:
[[email protected] conf]# vim/etc/httpd/conf/httpd.conf # Modify Red tag content
alias/phpmyadmin/"/usr/local/phpmyadmin/"
<directory "/usr/local/phpmyadmin/" >
Options-indexes followsymlinks #在Indexes Front plus-minus sign, this directory does not have the default home page, the directory is forbidden to display
AllowOverride None
Order Deny,allow
Allow from all
</Directory>
Example 6: Turn on the soft link feature. Directly referencing content outside the Web site's root directory via software links
[Email protected] ~]# MKDIR/WEB2
[Email protected] ~]# echo test1 >/web2/a.html
[Email protected] ~]# ln-s/web2//var/www/html/web2
[Email protected] ~]# rm-rf/var/www/html/index.html
[Email protected] ~]# rm-rf/var/www/html/index.php
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/A4/BE/wKioL1mwyWbSPbHAAAARKMMotsk843.png-wh_500x0-wm_ 3-wmp_4-s_2496021093.png "style=" Float:none; "title=" 2.png "alt=" Wkiol1mwywbspbhaaaarkmmotsk843.png-wh_50 "/>
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/06/0E/wKiom1mwyYaDIhY8AAAlpMKN884928.png-wh_500x0-wm_ 3-wmp_4-s_953619647.png "style=" Float:none; "title=" 3.png "alt=" Wkiom1mwyyadihy8aaalpmkn884928.png-wh_50 "/>
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/06/0E/wKiom1mwyYjBqyaxAACJiQXZ4Yg675.png-wh_500x0-wm_ 3-wmp_4-s_2839281538.png "style=" Float:none; "title=" 4.png "alt=" Wkiom1mwyyjbqyaxaacjiqxz4yg675.png-wh_50 "/>
Ctrl+f5 forced Refresh
Example 7: The/usr/local/phpmyadmin/directory under the website is protected by the user authentication method. Set the/usr/local/phpmyadmin/directory to be accessed only by user name password.
Method One:
alias/phpmyadmin/"/usr/local/phpmyadmin/"
<directory "/usr/local/phpmyadmin/" >
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,allow
Allow from all
AuthType Basic
AuthName "MySQL admin software ..."
Authuserfile/etc/httpd/conf/passwd.secret
#require User Tom
#require User Tom Bob
Require Valid-user
</Directory>
Parameter description:
Authentication method: The first type is specified by the file
The second type is directly written to the configuration file, and multiple users are separated by spaces
AuthType Basic # 1) authtype command: Specifies the authentication type: Basic.
AuthName "MySQL admin software ..." #请不要动我的奶酪
# authname Command: Specifies the name of the authentication zone. The zone name is displayed to the user in the Prompt for authentication dialog box.
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/A4/BE/wKioL1mwyeKgUbBUAAC0zaRzeeg201.png-wh_500x0-wm_ 3-wmp_4-s_453661155.png "title=" 5.png "alt=" Wkiol1mwyekgubbuaac0zarzeeg201.png-wh_50 "/>
Generate an authentication account and password
[Email protected] ~]# Htpasswd-cm/etc/httpd/conf/passwd.secret RM
New Password:
Re-type New Password:
Adding Password for user rm
Verify:
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/A4/BE/wKioL1mwyfXw9TPyAAEx4xOcefQ336.png-wh_500x0-wm_ 3-wmp_4-s_2062673237.png "title=" 6.png "alt=" Wkiol1mwyfxw9tpyaaex4xocefq336.png-wh_50 "/>
Method Two:
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf
<directory "/usr/local/phpmyadmin/" >
Options Indexes multiviews FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
AllowOverride authconfig
</Directory>
# allowoverride Authconfig line indicates that user authentication is allowed for files in the/usr/local/phpmyadmin/directory.
[Email protected] ~]# vim/usr/local/phpmyadmin/.htaccess
AuthType Basic
AuthName "MySQL admin software by. htaccess"
Authuserfile/etc/httpd/conf/passwd.secret
#require User Tom
Require Valid-user
Use the program htpasswd that came with Apache to generate text that contains the user name and password
[Email protected] ~]# Htpasswd-cm/etc/httpd/conf/passwd.secret swk #指定用户
New Password:
Re-type New Password:
Adding Password for user swk
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/06/0E/wKiom1mwyifz0hvgAACuz9Eu_j8880.png-wh_500x0-wm_ 3-wmp_4-s_1662728923.png "title=" 7.png "alt=" Wkiom1mwyifz0hvgaacuz9eu_j8880.png-wh_50 "/>
This article is from the "Innocence" blog, be sure to keep this source http://innocence.blog.51cto.com/4313888/1963373
Apache Common parameters and examples