HTTP2.2 notes - configuration related

Keywords: vim

Profile related

Master profile:
     /etc/httpd/conf/httpd.conf
     /etc/httpd/conf.d/*.conf

Switch the working mode (prefork, wowrker, event)
Modify the parameters in the configuration file / etc/sysconfig/httpd (the service script corresponding to the configuration file is in / etc/rc.d/init.d/httpd)

HTTPD=/usr/sbin/httpd	#prefork working mode (multi process)
HTTPD=/usr/sbin/httpd.worker	#worker working mode (multithreading)
HTTPD=/usr/sbin/httpd.event	#Event working mode (event driven)

Log file / var/log/httpd/*


Accessing web pages based on Basic authentication

Note: both are defined in the global, and the definition does not take effect in the virtual host

# mkdir /var/www/html/admin	#Create a directory that requires authentication access

Based on user authentication

<Directory "/var/www/html/admin/index.html">
	Options None
	AllowOverride None
	AuthType Basic	#Authentication mode
	AuthName "admin page"    #Tips for user access
	AuthUserFile "/etc/httpd/conf.d/.htpasswd"	#User password file
	Require user admin1 admin2    #Allow admin1 and admin2 access
</Directory>

# htpasswd -c -m /etc/httpd/conf.d/.htpasswd admin1
//Note: create admin1 user
-c: Automatically create user password file.htpasswd,Used only when the user is first created, otherwise it will be overwritten
-m: Use md5 encryption

Group based authentication

<Directory "/var/www/html/admin/index.html">
Options None
AllowOverride None
AuthType Basic    #Authentication mode
AuthName "admin page"    #Tips for user access
AuthUserFile "/etc/httpd/conf.d/.htpasswd"    #User password file
AuthGroupFIle "etc/httpd/conf.d/.htgroup"    #Group file
Require group group1    #Users allowed to access
</Directory>

//Group files manually created
# vim /etc/httpd/conf.d/.htgroup
/*The content format is as follows, each line defines a group
	group1:admin1 admin2
*/


Virtual host definition

Note: for the user-defined directory (for resources not under / var/www directory, please pay attention to the access rights), note out the DocumentRoot line to avoid the mixed use of the center / virtual host;

Virtual host format:

<VirtualHost 172.27.100.1:80>
	ServerName www.vhost1.com
	DocumentRoot "/vhost/web/html"
	#Other options are almost the same as configuring the primary server
	#Access control, error log, alias, etc
</VirtualHost>

Based on ip address

Use different ip to configure different hosts, usually

<VirtualHost 172.27.100.1:80>
	...
</VirtualHost>
<VirtualHost 172.27.100.2:80>
	...
</VirtualHost>

Based on host name

Configure multiple domain names on the same ip to access different virtual hosts through unified ip

NameVirtualHost 172.27.100.1:80    #The format of ip:port should be consistent with that of virtual host
<VirtualHost 172.27.100.1:80>
	ServerName www.test1.com
	DocumentRoot /var/www/vhosts/web1
	...
</VirtualHost>
<VirtualHost 172.27.100.1:80>
	ServerName www.test2.com
	DocumentRoot /var/www/vhosts/web2
	...
</VirtualHost>

Port based

Listening to different ports on the same ip to access different virtual hosts is not recommended

<VirtualHost 172.27.100.1:80>
	...
</VirtualHost>
<VirtualHost 172.27.100.1:8080>
	...
</VirtualHost>

Posted by it2051229 on Fri, 01 Nov 2019 19:04:12 -0700