Set up WEB servers in LINUX

Source: Internet
Author: User
The configuration time on my local machine is not long, but it took a long time to write a configuration document and share it with you. I hope you can use the LINUX release: Fedora14 and Apache.2.2 to install it! Still use the rpm Package installation method. Next, go to the question: httpd. conf configuration file...

 

The configuration time on my local machine is not long, but it took a long time to write a configuration document and share it with you. I hope it will be useful to you.

LINUX: Fedora 14, Apache. 2.2

No more installation! If you still use the rpm Package installation method, go to the topic below:

Httpd. conf configuration file introduction

1. options related to Apache networks and systems

# Use the ServerRoot parameter to set the Apache installation directory

# ServerRoot: The top of the directory tree under which the server's

# Configuration, error, and log files are kept.

# You will save yourself a lot of trouble.

# Do NOT add a slash at the end of the directory path.

#

ServerRoot "/etc/httpd"

# Use the Listen parameter to set the Apache listening port. the default value of Apache is 80.

Listen 80

# Use the User parameter to set the Apache process executor

User apache

# Use the Group parameter to set the user Group to which the Apache process executor belongs

Group apache

# Use the ServerAdmin parameter to set the email address of the website administrator

2. options related to Apache file and directory permissions

# Use the DocumentRoot parameter to set the website root directory

# DocumentRoot: The directory out of which you will serve your

# Events. By default, all requests are taken from this directory,

# Symbolic links and aliases may be used to point to other locations.

#

DocumentRoot "/var/www/html"

# Use Directory segments to set root Directory permissions

Options FollowSymLinks

AllowOverride None

# Use the Directory segment to set/var/www/html Directory permissions

Options Indexes FollowSymLinks

AllowOverride None

Order allow, deny

Allow from all

Set the homepage to index.html.

DirectoryIndex index.html. var

# The access permission control of the. ht suffix file works with AllowOverride in the upper directory.

# The following lines prevent. htaccess and. htpasswd files from being

# Viewed by Web clients.

#

Order allow, deny

Deny from all

Satisfy All

3. the options related to Apache logs are as follows:

# Use the ErrorLog parameter to set the location of the error log

# ErrorLog: The location of the error log file.

# If you do not specify an ErrorLog directive within

# Container, error messages relating to that virtual host will be

# Logged here. If you * do * define an error logfile for

# Container, that host's errors will be logged there and not here.

#

ErrorLog logs/error_log

# Use the LogLevel parameter to set the error log level

# LogLevel: Control the number of messages logged to the error_log.

# Possible values include: debug, info, notice, warn, error, crit,

# Alert, emerg.

#

LogLevel warn

# Use the LogFormat parameter to set an access log format Template

# The following directives define some format nicknames for use

# A CustomLog directive (see below ).

#

LogFormat "% h % l % u % t \" % r \ "%> s % B \" % {Referer} I \ "\" % {User-Agent} I \ "" combined

LogFormat "% h % l % u % t \" % r \ "%> s % B" common

LogFormat "% {Referer} I-> % U" referer

LogFormat "% {User-agent} I" agent

# Use the CustomLog parameter to set an access log format Template

# For a single logfile with access, agent, and referer information

# (Combined Logfile Format), use the following directive:

#

CustomLog logs/access_log combined

4. Explanation of relevant parameters

1) ServerRoot parameter: specifies the directory for installing Apache software.

2) the Listen parameter is used to specify the port listened to by Apache. by default, the listening port of Apache is 80. when the server has multiple IP addresses, the Listen parameter can also be used to set the IP address of the listener.

3) the User and Group parameters are used to specify the User Group to which the Apache process executor and executor belong. if you want to use UIG or GID, you must add the # sign before the ID.

4) The ServerAdmin parameter is used to specify the email address of the Web administrator. this address may appear when a system connection error occurs, so that visitors can promptly notify the WEB administrator.

5) DocumentRoot: specifies the location where documents are stored on the Web server. If no virtual host or directory is configured, you can access the WEB server over http, all output data files are stored here.

6) ErrorLog is used to specify the location of the log file for recording the error information generated during Apache operation, so that the system administrator can detect and resolve the fault.

5. symbolic links and virtual directories

1) a virtual directory is a way to add content other than the root directory to the site. The setting method is as follows:

# Use the Alias parameter to set the ing between the virtual directory and the actual directory

Alias/lopn/var/www/lopn

# Use the Directory segment to set the/var/www // lopn Directory access permission

..........................................

In this case, restart the server and use the domain name or IP address/lopn to access

2) symbolic link: at that time, symbolic links implement the same functions as virtual directories, but the implementation mechanism is different!

In addition, for example, to use symbolic links, you do not need to modify the configuration file. you only need to create a connection in the root directory and run the following command:

# Ln-s/var/www/lopn

In this case, you can access the content under/var/www/lopn through the domain name or IP/lopn.

 

6. personal space

A local account with an account can use Apache to publish its own things. assume that a user lopn is released at http: // host /~ Lopn

Next we start to configure

  // Indicates loading this module, indicating apache opens the personal space function

#

# UserDir is disabled by default since it can confirm the presence

# Of a username on the system (depending on home directory

# Permissions ).

#

UserDir disabled root/prohibit root users from publishing

#

# To enable requests /~ User/to serve the user's public_html

# Directory, remove the "UserDir disabled" line above, and uncomment

# The following line instead:

#

# UserDir public_html/remove the annotator to enable the function, indicating that the public_html content under the personal user directory is published

 

Next, you need to set the directory permissions as follows. apache provides the default settings and removes the # number, as shown below.

# Control access to UserDir directories. The following is an example

# For a site where these directories are restricted to read-only.

#

 

AllowOverride FileInfo AuthConfig Limit

Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

Order allow, deny

Allow from all

Order deny, allow

Deny from all

 

#

In this way, the personal space is configured. However, pay attention to permission settings when setting

7. Apache Security Configuration

Apache provides a variety of security control methods, including WEB access control, user logon authentication, and. htaccess files.

1) access control

In the configuration file, the Direcotry segment is used to set Directory-related parameters and commands, including access control and authentication.

 

Directory-related configuration parameters and commands

 

Related commands: 1. the Allow command is used to set which clients can ask Apache. the format is as follows:

Allow from [All/full domain name/partial domain name/IP address/network address/CIDR address]

2. the Deny command is used to set which clients are denied access to Apache. the format is the same as that of Allow.

3. The Order command is used to specify the sequence in which access rules are executed.

Order Allow, Deny: first execute a permit-filling access rule, and then execute a Deny access rule

Order Deny, Allow

2) User Authentication

Apache user authentication includes Basic authentication and Digest authentication. Here we will only discuss the basic authentication

Basic authentication: When a Web browser requests a URL protected by this authentication mode, a dialog box appears asking you to enter the user name and password. If yes, the page is returned; otherwise, error 401 is returned.

To use user authentication, you must first create an authentication password file that saves the user name and password. Run the following command:

# Htpasswd-c/etc/httpd/conf/users lopn * create an authentication password file named users in the/etc/httpd/conf directory and add a user named lopn

# Htpasswd/etc/httpd/conf/users xrp * indicates adding an xrp user

With the authentication password file, we need to change the configuration file.

 

#

# Options Indexes FollowSymlinks

# AllowOverride None

#

# AuthType Basic * use the authtype parameter to set the authentication type

# AuthName domain name * Set the protected domain name on a daily basis. there is no restriction here. you can set it based on your preferences.

# AuthUserFile/etc/httpd/conf/users * use the AuthUserFile parameter to set the location of the authentication password file

# Require user lopn * set lopn users to access

# Require valid-user * grant permissions to all users in the authentication password file. select either of the above

#

# Order ......

#......

# </Directory>

3) distributed configuration file. htaccess

. Htaccess. This file can overwrite the configuration in the httpd. conf file, but it can only set access control for directories and user authentication .. There can be multiple htaccess files, and each. htaccess file is limited to the directory where the file is stored and all subdirectories under the Directory .. The functions that htaccess can implement can be implemented in the configuration file, but because the service does not need to be restarted after. htaccess modifies the configuration, it is sometimes very useful. The operation is as follows:

Open the configuration file and set

#

# * Allow the. htaccess file to overwrite the configuration of this directory in the httpd. conf file

# AllowOverride All

#

 

Then, go to the specified directory, create a. htaccess file, and write the configuration to take effect without restarting.

8. the description in the configuration file below the VM (based on the host name) is quite simple and will not be repeated here.

# NameVirtualHost *: 80

# All interfaces accept the request

# NOTE: NameVirtualHost cannot be used without a port specifier

# (E.g.: 80) if mod_ssl is being used, due to the nature of

# SSL protocol.

#

#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for requests without a known

# Server name.

#

#

# ServerAdmin webmaster@dummy-host.example.com

# DocumentRoot/www/docs/dummy-host.example.com

# ServerName dummy-host.example.com

# ErrorLog logs/dummy-host.example.com-error_log

# CustomLog logs/dummy-host.example.com-access_log common

#

It took us two days to write it. I hope it will be useful to everyone. haha! -Lopn

 

 

This article is from the lopnxrp blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.