In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces an example of building an Apache website service configuration based on Linux, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.
Apache, as an open source software, is one of the widely used web applications. Apache has two main versions 1.x and 2.x. Generally, we use version 2.x. Compared with version 1.x, it supports many new features. Download the Apache source code package from: https://httpd.apache.org, download it to the source package and prepare for installation:
1. To avoid port conflicts, program conflicts and other problems, if there is a httpd service installed in rpm mode, it is recommended to uninstall it.
2. Mount the system image, change to the Packages directory on the system disk, and install the related dependent packages (note, it is best to install them one by one, because if some installation packages have been installed, you will get an error if you install the following installation packages at once)
3. Unpack the httpd source code package, specify the release directory, and then switch to the expanded source code directory:
4. Configuration:
In the above configuration command, the meaning of each option is as follows:
-- prefix: specify the directory in which the httpd service will be installed.
-- enable-so: enable dynamic loading module support, so that httpd has the ability to further extend the function.
-- enable-rewrite: enables web address rewriting for website optimization and directory migration maintenance.
-- enable-charset-lite: enables character set support to support web pages encoded with various character sets.
-- enable-cgi: enable CGI script program support to expand the application access ability of the website.
5. Execute the make & & make install command to compile and install:
If in the above configuration, compilation, installation process reported errors, eliminate command errors under the premise, then generally less dependent package, check that the dependent package is not installed less!
6. After the installation is complete, after changing to the directory where the installation was successful, you will see the following directories:
The main subdirectories are used for the following purposes:
Bin: stores various execution program files for httpd services. It includes main program httpd, service control tool apachectl and so on.
Cgi-bin: store all kinds of CGI program files.
Logs: stores the log files of the httpd service.
Conf: stores various configuration files of the httpd service, including the main configuration file httpd.conf, the enhanced configuration subdirectory extra, etc.
Htdocs: stores web documents, including the default home page file index.html, etc.
Module: various module files for httpd services are stored.
7. Optimize the execution path (depending on the actual situation, it may not be optimized):
The httpd service installed through the source code belongs to a third-party service, so the program path is not in the default search path. If you want to start Apache now, you need to execute the command: / usr/local/httpd/bin/apachectl start, that is, the absolute path of the program control files in the bin directory after installation, plus the operations you need to do.
Then, to make this service easier to use, you can perform path optimization as follows:
Add symbolic links to related programs:
In this way, when executing relevant commands, you do not have to enter a long path. If you want to start the service, you can directly execute / usr/local/bin/apachectl start, but this is still not as convenient as controlling the system service. Then, you can continue to operate and add httpd system services in the following two ways:
Method 1
Copy the apachectl file to / etc/init.d/httpd, then edit the file,:
Make changes as follows, and then save the exit:
Add system services:
At this point, like the control system service, you can use systemctl start/status/restart httpd to control the apache service.
There is another way to add it as a system service, but you have to edit the configuration file, which is more troublesome. You can define the service further. If you don't have any special requirements, you can use the above method.
Method 2:
Establish a httpd.service configuration file (pay attention to the path of the configuration file, where the apachectl path written in the configuration file depends on the actual situation)
The functions of the configuration items in the configuration file are as follows:
Each of the two methods has its own advantages. Method 2 can define the service in detail, and you can also use systemctl enable httpd.service to set the httpd service to boot automatically, which cannot be realized by method 1.
When the control of the service is optimized, the httpd service can be basically configured:
1. Edit the main configuration file httpd.conf of the httpd service
Execute / ServerName in the last line mode, and add a line nearby: ServiceName www.aaa.com, which is used to set the domain name for the website. As follows:
Enter the last line mode to find ServerName:
After modifying the configuration content of the httpd.conf file, you can use the command apachectl-t or httpd-t to check the syntax of the configuration content. If there are no errors, it will be displayed as follows:
2. Deploy web documents:
For the newly compiled and installed httpd service, the root directory of the site is located under / usr/local/httpd/htdocs, and you need to copy or upload the web documents of the web site to this directory.
3. Check the access to the web site
The httpd server uses two types of logs: access logs and error logs. The file names of these two kinds of logs are acces_log and error_log, respectively, and both are in the / usr/local/httpd/logs directory. You can use the command tail-f / usr/local/httpd/logs/access_log to dynamically view website visits.
4. The most important httpd.conf main configuration file
The comment lines in httpd.conf start with "#", and the rest are set lines. According to the scope of the configuration, the setting line can be divided into global configuration and regional configuration. Each global configuration is a separate configuration and does not need to be included in other task areas. Some common global configuration items are used as follows:
With the exception of global configuration items, most configurations in the httpd.conf file are included in the zone. The zone configuration uses a pair of combination tags to limit the scope of the configuration item, as follows:
Thank you for reading this article carefully. I hope the article "an example of building an Apache website service configuration based on Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.