Apache Virtual Host virtual host configuration and rewrite parameter description

  • 2020-05-15 02:44:08
  • OfStack

Virtual Host configuration process

So our path in this example is going to look like this
DocumentRoot: / home/jb51 / sites/demo ofstack. com
ServerName: demo. ofstack. com

1. Enter the apache virtual host setup directory


cd /etc/apache2/sites-available 

2. Create the file demo.ofstack.com


<VirtualHost *:80> 
    ServerAdmin webmaster@localhost 
    DirectoryIndex index.html index.php 
    DocumentRoot /home/jb51 /sites/demo.ofstack.com 
    ServerName demo.ofstack.com 
    ServerAlias demo.ofstack.com 
    <Directory "/home/jb51 /sites/demo.ofstack.com"> 
        allow from all Options + Indexes 
    </Directory> 
</VirtualHost> 


3. Activate the virtual host configuration


sudo a2ensite demo.ofstack.com 


4. Enter /etc/apache2/ sites-enabled/directory to view all the active virtual hosts. You can log off with sudo a2dissite demo.ofstack.com


cd /etc/apache2/sites-enabled 
ls -lt 

According to


lrwxrwxrwx 1 root root 36 2013-04-05 17:29 demo.ofstack.com -> ../sites-available/demo.ofstack.com 


5. Restart the apache service


sudo /etc/init.d/apache2 restart 


6. host ubuntu Settings


vim /etc/hosts 



127.0.0.1 demo.ofstack.com


7. < Directory > Set to enable.htaccess with display directory structure list


<Directory "/home/jb51 /demo.ofstack.com"> 
AllowOverride none 
AllowOverride all 
Options -Indexes FollowSymLinks 
</Directory> 

AllowOverride none means close.htaccess, if you want to open it, you can set AllowOverride all
Options-Indexes means close the directory structure display. If you want to turn it on, you can set it to Options Indexes
Options FollowSymLinks means support for symbol link (soft connection), which can be set to Options-FollowSymLinks if you want to close it

Important parameters of rewrite module

Open rewrite:


sudo a2enmod rewrite 

Stop using rewrite:


sudo a2dismod rewrite 

Server environment variables: the environment variables provided by Apache to the rewirte module are roughly divided into five types.

Part 1: HTTP headers partial parameters

1. Parameter name: HTTP_USER_AGENT
Sample reference value: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh - CN; rv: Gecko / 2009032609 Firefox / 3.0.8 1.9.0.8)
Note: equivalent to the server parameter in PHP: $_SERVER["HTTP_USER_AGENT"]

2. Parameter name: HTTP_REFERER
Sample reference: http: / / www test. cn/test php
Note: equivalent to the server parameter in PHP: _SERVER["HTTP_REFERER"]

3. Parameter name: HTTP_COOKIE
Sample reference values: ZDEDebuggerPresent=php,phtml,php3
Note: equivalent to the server parameter in PHP: $_SERVER["HTTP_COOKIE"]

4. Parameter name: HTTP_FORWARDED
Sample reference value: the IP address of the proxy server will be used if the proxy server is used. It is not easy to test the value against the local environment.
Note: equivalent to the server parameter in PHP: $_SERVER["HTTP_FORWARDED"]

5. Parameter name: HTTP_HOST
Sample reference value: www.test.com
Note: equivalent to the server parameter in PHP: $_SERVER["HTTP_HOST"]

6. Parameter name: HTTP_PROXY_CONNECTION
Sample reference value: network connection agent information. Same as HTTP_FORWARDED parameter 1. It is not easy to test the value in the local environment.
Note: PHP does not appear to provide such a server information value. If so, it may be equivalent to: $_SERVER["HTTP_PROXY_CONNECTION"]

7. Parameter name: HTTP_ACCEPT
The sample reference: text/html, application/xhtml + xml, application/xml; q = 0.9 * / *; q = 0.8
Note: equivalent to the server parameter in PHP: $_SERVER["HTTP_ACCEPT"]

Part 2: server internals partial parameters

1. Parameter name: DOCUMENT_ROOT
Sample reference value: C:/webRoot/t
Note: equivalent to the server parameter in PHP: $_SERVER["DOCUMENT_ROOT"]

2. Parameter name: SERVER_ADMIN
Sample reference value: youemailaddress@gmail.com
Note: equivalent to the server parameter in PHP: $_SERVER["SERVER_ADMIN"]

3. Parameter name: SERVER_NAME
Sample reference value: www.test.com
Note: equivalent to the server parameter in PHP: $_SERVER["SERVER_NAME"]

4. Parameter name: SERVER_ADDR
Sample reference value: 127.0.0.1
Note: equivalent to the server parameter in PHP: $_SERVER["SERVER_ADDR"]

5. Parameter name: SERVER_PORT
Sample reference value: 80
Note: equivalent to the server parameter in PHP: $_SERVER["SERVER_PORT"]

6. Parameter name: SERVER_PROTOCOL
Sample reference value: HTTP/1.1
Note: equivalent to the server parameter in PHP: $_SERVER["SERVER_PROTOCOL"]

7. Parameter name: SERVER_SOFTWARE
Sample reference value: Apache/2.2.11 (Win32) PHP/5.2.9-1
Note: equivalent to the server parameter in PHP: $_SERVER["SERVER_SOFTWARE"]

Part 3: connection & request part parameters

1. Parameter name: REMOTE_ADDR
Sample reference value: 127.0.0.1 IP address of the user browsing the current page.
Note: equivalent to the server parameter in PHP: $_SERVER["REMOTE_ADDR"]

2. Parameter name: REMOTE_HOST
Sample reference value: 127.0.0.1 host name of the user browsing the current page. Reverse domain name resolution is based on the user's REMOTE_ADDR
Note: equivalent to the server parameter in PHP: $_SERVER["REMOTE_HOST"]

3. Parameter name: REMOTE_PORT
Sample reference value: 2574 (variable value) the port used by the user when connecting to the server
Note: equivalent to the server parameter in PHP: $_SERVER["REMOTE_PORT"]

4. Parameter name: REMOTE_USER
Sample reference value: null
Note: PHP does not appear to provide the associated $_SERVER value.

5. Parameter name: REMOTE_IDENT
Sample reference value: null
Note: PHP does not appear to provide the associated $_SERVER value.

6. Parameter name: REQUEST_METHOD
Sample reference value: GET
Note: equivalent to the server parameter in PHP: $_SERVER["REQUEST_METHOD"]

7. Parameter name: SCRIPT_FILENAME
Sample reference: C: / webRoot t/share77 html
Note: equivalent to PHP server parameter: $_SERVER["SCRIPT_FILENAME"]

8. Parameter name: PATH_INFO
Sample reference value: null
Note: equivalent to the server parameter in PHP: $_REQUEST["PATH_INFO"]

9. Parameter name: QUERY_STRING
Sample reference value: a=b&c=d&e=f
Note: equivalent to the server parameter in PHP: $_SERVER["QUERY_STRING"]

10. Parameter name: AUTH_TYPE
Sample reference value: null when PHP is running in Apache module mode and is using HTTP authentication, this is the type of authentication
Note: equivalent to the server parameter in PHP: $_SERVER["AUTH_TYPE"]

Part 4: date and time part parameters

1. Parameter name: TIME_YEAR
Sample reference value: 2009
Note: the server gets the current year value

2. Parameter name: TIME_MON
Sample reference value: 04
Note: the server gets the current month value

3. Parameter name: TIME_DAY
Sample reference value: 22
The server gets the current daily value

4. Parameter name: TIME_HOUR
Sample reference value: 16
The server gets the hour of the current time

5. Parameter name: TIME_MIN
Sample reference value: 26
The server gets the current time in minutes

6. Parameter name: TIME_SEC
Sample reference value: 34
The server gets the current time in seconds

7. Parameter name: TIME_WDAY
Sample reference value: 3
The server gets the day of the week, from Sunday to Saturday, Numbers from 0 to 6

8. Parameter name: TIME
Sample reference value: 20090422162634
Server to get the current time, the format is: month, month, hour, minute, second

Part 5: specials partial parameters

1. Parameter name: API_VERSION
Sample reference value: 20051115:21
Description: apache API version information.

2. Parameter name: THE_REQUEST
Sample reference value: GET/share77.html HTTP/1.1
Note: the browser to the server request value. Does not include other header information.

3. Parameter name: REQUEST_URI
Sample reference value: / share77.html
Browser requests resource information.

4. Parameter name: REQUEST_FILENAME
Sample reference: C: / webRoot t/share77 html
The physical address of the requested resource on disk.

5. Parameter name: IS_SUBREQ
Sample reference value: false
Note: if it is sub-request, it will be true; otherwise, it will be false.

6. Parameter name: HTTPS
Sample reference value: off
Note: if the connection is in SSL/TLS mode, the value is on; otherwise, the value is off. This parameter is safe, even if the mod_ssl module is not loaded.


Related articles: