Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Apache built by Linux system service

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Www: world wide web World wide Web

Http protocol: hypertext transfer protocol

HTML language: hypertext markup language index.html

2. URL: 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

Linux apache+mysql+php

Nginx

I. relevant 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/

II. Configuration file

Note: apache configuration files are strictly case-sensitive

1. Basic configuration for host environment

ServerRoot apache 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

Include etc/extra/httpd-vhosts.conf

The content in the subconfiguration file will also be loaded and effective.

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

AllowOverrideNone

# define whether to allow a directory

Permissions in the .htaccess file 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

The following five examples are inserted under the Require allgranted tight (very important)

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

Three or 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 fullyqualified 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.

1. Open the apache main configuration file

# Includeetc//extra/httpd-autoindex.conf (remove #)

two。 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

3. Restart the apache service:

/ usr/local/apache2/bin/apachectlstop

/ usr/local/apache2/bin/apachectlstart

Note: restarting the apache installed in the source code package needs to be closed before starting.

4. Verify the test results:

Open the browser to enter the server IP/a/ (the last "/" must be present)

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 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

AuthTypebasic # 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)

Requirevalid-user # allows all users in the password file to access

3. Use the command to generate the password file apache.passwd and join the users who are allowed to access it. (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:

1) IP-based virtual host: one server, multiple ip, building multiple websites

Ifconfig eth0:0 IP # establish a network card sub-port

2) Port-based virtual host: one server, one ip, build multiple websites, and each network uses different ports to access

3) name-based virtual host: one server, one ip, build multiple websites, each website is accessed using a different domain name

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 system: C:\ WINDOWS\ system32\ drivers\ etc\ hosts

In Linux system: / 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

# modify the main configuration file to enable file association

Include etc//extra/httpd-vhosts.conf # this line is uncommented

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.

IV. 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.

5. Virtual host after yum installs apache

Objective: to realize the collocation of apache virtual host and DNS.

Application technology: domain name-based virtual host and IP-based virtual host

Premise: 1. A WEB server with dual network cards, eth0-192.168.115.195

Eth2-192.168.115.199

2. A DNS server eth0-192.168.115.194

3. A client 192.168.115.200

5.1. Planning

Website IP DocumentRoot ServerAdmin

-www.163.com 192.168.115.195 / www/163.com www.163.com

Www.sina.com 192.168.115.195 / www/sina.com www.sina.com

Www.sohu.com 192.168.115.195 / www/sohu.com www.sohu.com

Www.baidu.com 192.168.115.199 / www/baidu.com www.baidu.com

Www.baidu.com is based on IP

5.2.Configuring DNS server

5.2.1. Configure local yum source and install software bind

Start the service service named start

5.2.2. Configure network card service and restart network service

Service network restart

5.2.3. Configure the main configuration file named.conf

Delete all other redundant lines and save only the following

5.2.4, configuration data configuration file

Create a forward resolution file for the relevant domain name and change the owner to named

Configure the forward resolution files for each related domain name

163.com

Sina.com

Sohu.com

Baidu.com (IP-based virtual host)

Restart the DNS service service named restart

5.3. configure 115.200 client test

The Win client is used here and the configuration is as follows:

test

5.4. configure the apache server

5.4.1. Configure the network card and restart the network service

Eth0

Eth2

Restart the network service service network restart

5.4.2. Configure the local yum source and install httpd

Yum-y install httpd

Service httpd start

5.4.3, create related catalogs and home pages

The warning message does not appear when the service is restarted

Vi / etc/httpd/conf/httpd.conf

Change ServerName www.example.com:80 / / to 192.168.115.195pur80

Configure Apache to realize virtual host

Vi / etc/httpd/conf/httpd.conf

NameVirtualHost *: 80 beat / changed to NameVirtualHost 192.168.115.195pur80 IP IP is the native IP

NameVirtualHost 192.168.115.195purl 80 supports virtual hosts based on hostname

Add the following at the bottom of the vi / etc/httpd/conf/httpd.conf main configuration file

5.4.4, test verification

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report