In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Apache server
1www: world wide web World wide Web
Http protocol: hypertext transfer protocol
HTML language: hypertext markup language index.html
2URL: unified Resource location: protocol + Domain name: Port + Web File name
Http://www.baidu.com:80/phpmyadmin/index.php
3 the method of building the server of www
Windows IIS + asp + SQLserver
IIS: Internet Information server
Linuxapache+mysql+php
Nginx
Related documents
Apache profile
Source package installation: / usr/lcoal/apache2/etc/httpd.conf (main configuration file)
/ usr/local/apache/etc/extra/*.conf (subprofile)
Rpm package installation: / etc/httpd/conf/httpd.conf
Where to save the web page:
Source code package: / usr/local/apache2/htdocs/
Rpm package installation: / var/www/html/
Log save location
Source code package: / usr/local/apache2/logs/
Rpm package: / var/log/httpd/
Configuration file
Note: apache configuration files are strictly case-sensitive
1 basic configuration for the host environment
ServerRootapache home directory / usr/local/apache2
Listen listening port: 80
Related modules loaded by LoadModule php5
User
Group users and groups
ServerAdmin administrator mailbox
ServerName server name (temporary resolution is used when there is no domain name resolution. Not enabled by default)
ErrorLog "logs/error_log error log
CustomLog "logs/access_log" common correct access log
DirectoryIndex index.html index.php default web page file name, priority order
The contents of the Include etc/extra/httpd- vhosts.confs subconfiguration file will also load and take effect.
2 home page directory and permissions
DocumentRoot "/ usr/local/apache2//htdocs"
# Web file storage directory (default)
# define permissions for a specified directory
Options Indexes FollowSymLinks
# options
None: without any additional permissions
All: all permissions
Indexes: browse permissions (display directory contents when there is no default web page file in this directory)
FollowSymLinks: allow soft connections to other directories
AllowOverride None
# define whether permissions in .htaccess files under the directory are allowed to take effect
Permissions do not take effect in None:.htaccess
All: all permissions in the file take effect
AuthConfig: in the file, only the permission of web page authentication takes effect.
Require all granted access Control list
# define the allowed access permissions for this directory
Example 1: only hosts with IP 192.168.1.1 are allowed to access
Require all granted
Require ip 192.168.1.1
Example 2: only hosts on the 192.168.0.0ax 24 network are allowed to access
Require all granted
Require ip 192.168.1.0/24
Example 3: host access to 192.168.1.2 is prohibited, while others are allowed.
Require all granted
Require not ip 192.168.1.2
Example 4: allow all access
Require all granted
Example 5: deny all access
Require all denied
Four small experiments
Experimental environment:
Experiment with apache installed in lamp environment
After the installation is complete, start apache to verify whether the installation is successful and whether the home page is accessible.
Note: found startup service error: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Solution: open the main configuration file httpd.conf
Search for ServerName (about 200 lines)
Change to ServerName localhost:80 (and remove the previous # comment)
Experiment 1: directory aliases
You can make specific website programs do not appear under the root directory of the site, and in this way, you can avoid confusion and conflict with the original program itself; shorten the depth of the web directory and reduce the length of the URL.
Open the apache main configuration file
# Include etc//extra/httpd-autoindex.conf (remove #)
Go to the subprofile directory extra and open httpd-autoindex.conf
Write an alias following the example:
Alias / a / "/ www/a/" # the actual directory ends with /
Options Indexes MultiViews
AllowOverride None
Require all granted
Manually create the index.html file in the / www/a/ directory
Restart the apache service:
/ usr/local/apache2/bin/apachectl stop
/ usr/local/apache2/bin/apachectl start
Note: restarting the apache installed in the source code package needs to be closed before starting.
Verify the test results:
Open a browser and enter the server IP/a/
Experiment 2: user authentication
Improve the security of the website, protect the information of individual pages, restrict specific directories, and only specified users can access it.
1. Open the main configuration file and add it at the bottom:
# protected directory
Options Indexes
AllowOverride All # (Open permission authentication file .htaccess)
Require all granted
two。 Create a permissions file in the specified directory:
Cd / usr/local/apache2/htdocs/baohu
Vi .htaccess # add the following
AuthName "50 docs"
# prompt message
AuthType basic
# encryption type
AuthUserFile / usr/local/apache2/htdocs/baohu/apache.passwd
# password file, the file name is customized. (but the path should be right, use the absolute path)
Require valid-user
# allow all users in the password file to access
3. Create a password file and add users who are allowed to access. (this user has nothing to do with the system user)
Htpasswd-c / usr/local/apache2/htdocs/baohu/apache.passwd test1
-c establish a password file, and only when the first user is added can-c
Htpasswd-m / usr/local/apache2/htdocs/baohu/apache.passwd test2
-m when you add more users, use the-m parameter
4. Verify access: (create index.html files in the directory manually)
Browser input server IP/baohu/index.html
Experiment 3: * Virtual host * *
Classification of virtual hosts:
IP-based virtual host: one server, multiple ip, build multiple websites
Ifconfig eth0:0 IP # establish a network card sub-port
Port-based virtual host: one server, one ip, build multiple websites, each network uses different ports to access
Name-based virtual host: a server, an ip, build multiple websites, each using a different domain name access
1. Experimental construction (preparatory work)
a. Domain name resolution: prepare two domain names
Www.sohu.com
Www.sina.com
b. No DNS has been built, so it can only be manually added to the local hosts file for resolution.
In Windows systems:
C:\ WINDOWS\ system32\ drivers\ etc\ hosts
In Linux systems:
/ etc/hosts
c. Website home page directory planning
Create sohu and sina directories under the / / htdocs/ directory
And create index.html files in the newly created directory (write different contents respectively)
two。 Lab process (modify configuration file)
A.vi / usr/local/apache2/etc/httpd.conf# modifies the main configuration file to enable file association
Include etc//extra/httpd-vhosts.conf# uncomment this line
B.vi / usr/local/apache2/etc/extra/ httpd-vhosts.conf
# add the following content (delete the existing example before adding)
Options Indexes
AllowOverride None
Require all granted
Options Indexes
AllowOverride None
Require all granted
# Virtual Host label
ServerAdmin webmaster@sina.com# administrator mailbox
DocumentRoot "/ usr/local/apache2/htdocs/sina" # website home directory
ServerName www.sina.com# full domain name
ErrorLog "logs/sina-error_log" # error log
CustomLog "logs/sina-access_log" common# access Log
ServerAdmin webmaster@sohu.com
DocumentRoot "/ usr/local/apache2/htdocs/sohu"
ServerName www.sohu.com
ErrorLog "logs/sohu.com-error_log"
CustomLog "logs/sohu.com-access_log" common
c. Restart the service to verify the results
Under Windows: enter two different domain names to verify the content of the web page under the browser
Under Linux: verify the elinks domain name by elinks command
Experiment 4: rewrite rewriting function
Entering an address in URL will automatically jump to another, which is mostly used to change websites or add new domain names.
Experimental requirements:
A virtual host can be accessed normally
B Open the main configuration file and open the rewriting module
LoadModule rewrite_module modules/mod_rewrite.so# uncomment
Domain name jump experiment:
1. Modify virtual host configuration file
Vi * / extra/httpd-vhosts.conf
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
two。 Create a rule matching file
Vi * / .htaccess # is created under the specified web page directory
RewriteEngine on
# enable rewrite function
RewriteCond {HTTP_HOST} www.sina.com
# assign content starting with www.sina.com to HTTP_HOST variable
RewriteRule. * http://www.sohu.com
#. * enter any address and jump to http://www.sohu.com
3. Restart the server for access verification
Static to dynamic jump:
1. Modify virtual host configuration file
Vi * / extra/httpd-vhosts.conf
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
two。 Create a rule file
Vi * / .htaccess
RewriteEngine on
RewriteRule index (\ d +) .html index.php?id=$1
# when entering index (numeric value) .html, jump to the index.php file
3. Restart the service for access verification
Verification method: create a new index.php file in the * / htdocs/sohu/ directory
Visit www.sohu.com/index. Html to see if you are visiting your index.php web page
Note: the experiment of jumping from static web pages to dynamic web pages can only be accessed in a complete lamp environment.
Six common subprofiles
Httpd-default.conf # apache thread control, must be enabled
Timeout 300 # timeout
KeepAlive On
# enable thread control (if it is not enabled, users accessing the page will generate one process, while visiting other pages will generate another process. In this way, a user will generate many processes, which will degrade apache performance. When this option is turned on, a process will be generated when the user visits the site, and threads will be generated when other pages are opened, ensuring that only one process will be generated by a user. This function of the website must be enabled. )
MaxKeepAliveRequests 100 # maximum number of thread connections
Httpd-info.conf # apache status Statistics
SetHandler server-status
Order deny,allow
Deny from all
Allow from .example.com
# you can view the apache status by accessing www.domain.com/server-status. If the page displays not found, you need to modify the directory permissions by adding allow from ip (allowed ip) under Deny from all.
Httpd-manual.conf # apache help documentation
By visiting www.domain.com/manual to view apache help documents, generally in English, useless, you can go to the apache official website to download help documents.
Httpd-languages.conf # language coding
For it to take effect, it needs to be opened in the main configuration file, if the Chinese garbled is not encoded by the browser, the reason may be that the profile comment is not open.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.