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/01 Report--
This article mainly explains "how to build Nginx on CentOS7". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to build Nginx on CentOS7".
Environment required before installation
Before Nginx installation, you need an environment: wget, gcc, pcre, openssl, zlib1,wget, which is used to download plug-ins from the external network:
Yum-y install wget
GCC (GNU Compiler Collection,GNU Compiler Suite) is a programming language compiler developed by GNU. Originally as the official compiler of GNU operating system, GCC has been adopted as a standard compiler by most Unix-like operating systems (such as Linux, BSD, Mac OS X, etc.).
Yum install gcc-c++
3 Perl Compatible Regular Expressions installation, which is a Perl library, including a perl-compatible regular expression library. Nginx's http module uses pcre to parse regular expressions, so you need to install the pcre library on linux
Yum install-y pcre pcre-devel
4 nginx OpenSSL: it is a powerful secure socket layer password library, including major cryptographic algorithms, commonly used key and certificate encapsulation management functions and SSL protocol, and provides rich applications for testing or other purposes. Nginx not only supports http protocol, but also supports https (that is, transmitting http over ssl protocol), so you need to install openssl library on linux.
Yum install-y openssl openssl-devel
5 http zlib: it provides many ways to compress and decompress. Nginx uses zlib to gzip the contents of the http package, so you need to install the zlib library on linux
Yum install-y openssl openssl-devel
Nginx installation
It's not easy. After the above steps, we finally installed the required environment, and then the Nginx installation started.
1. Enter a directory (any directory can be used to store the downloaded Nginx installation package. Here, take entering the / root directory as an example. If you log in with your root account, the default is / root. This is why A Fan uses this directory, which is lazy.)
Enter directory command: cd / root
Download the nginx installation package and use case nginx1.10.3 for this article (the latest version can be viewed on the official website http://nginx.org/download)
Download command: wget http://nginx.org/download/nginx-1.10.3.tar.gz
2. Decompress the tar package of Nginx
Decompression command: tar-zxvf nginx-1.10.3.tar.gz
3. Check whether the decompression is successful.
Command: ls
As shown in the picture, you can see that the decompression is successful.
4. Enter the directory that has just been extracted
Command: cd nginx-1.10.3
Configure (here point the Nginx installation to the / usr/local/src/nginx/ directory)
Command:. / configure-- prefix=/usr/local/src/nginx/
Find that there will be a lot of lines of information, do not be afraid, it is normal information
5, compile and install
Command: make & & make install
6. The whole verification, compilation and installation process should not report any errors. If you set the installation target directory using prefix in the previous process, you also need to set the environment variables in the / etc/profile file (Note: environment variables generally refer to some parameters used in the operating system to specify the operating system environment, which is equivalent to setting a quick path to startup software (such as mysql/jdk), which is convenient to use.
Command: vi / etc/profile
Add to the configuration file:
Export NGINX_HOME=/usr/local/src/nginxexport PATH=$NGINX_HOME/sbin:$PATH
Because there are a lot of things messing around with Pink, so the configuration file here doesn't have to be the same as Pink's.
7 to make the environment variable effective
Command: source / etc/profile
8, check whether the installation is successful:
Go to the etc directory (cd / etc) and execute the command: nginx-t. If it is incorrect, it will give the corresponding error prompt.
What I am giving here is the correct hint that we have installed it correctly.
9. Configure the Nginx configuration file. The location of the Nginx configuration file is: / usr/local/src/nginx/conf/nginx.conf (depending on your own location):
Vi / usr/local/src/nginx/conf/nginx.conf
10, modify the configuration file to nginx.conf in conf under the Nginx installation directory, command:
/ usr/local/src/nginx/sbin/nginx-c / usr/local/src/nginx/conf/nginx.conf
11, start nginx, command:
Nginx
12. Test, access the address just configured in the configuration file externally with a browser when Nginx is started, as shown in the figure, it is a success.
Possible problems:
When using a browser externally, the access address may not be accessible.
Cause of the problem: Port 80 is not open, or the firewall is not turned off
Based on security considerations, it is recommended to open port 80.
1, open port 80 (please note that make sure the firewall is on at this time, otherwise there is no point in doing this step):
Open port command: firewall-cmd-- zone=public-- add-port=80/tcp-- permanent restart firewall: systemctl restart firewalld.service command meaning:-- zone # scope-- add-port=80/tcp # add port, format: Port / communication protocol-- permanent # takes effect permanently, without this parameter, it becomes invalid after restart
Or simply turn off the firewall:
Service firewalld stop
Just choose one of these two operations. At this point, the Nginx installation tutorial is over.
Set Nginx to boot automatically
In practice, it is found that if the machine is turned off and turned on again, it needs to be manually turned on again to access Nginx, which is certainly intolerable for us in pursuit of high efficiency, so let's talk about how to set Nginx to boot:
1. Go to the / lib/systemd/system/ directory and command:
Cd / lib/systemd/system/
2. Create a file, command:
Vi nginx.service
Copy the following to the file:
[Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/src/nginx/sbin/nginx ExecReload=/usr/local/src/nginx/sbin/nginx reload ExecStop=/usr/local/src/nginx/sbin/nginx quit PrivateTmp=true [Install] WantedBy=multi-user.target
Description: describe the service After: describe the service category
[Service] the setting of service operation parameters Type=forking is in the form of running in the background. The specific operation command ExecReload is the restart command ExecStop is the stop command PrivateTmp=True indicates that the service is allocated an independent temporary space. Note: the start, restart and stop commands of [Service] all require absolute paths.
[Install] the settings related to service installation under the runlevel can be set to multi-users, that is, the system runlevel is 3
3. After saving and exiting the file, execute the file to make Nginx boot effective, and execute the command:
Systemctl enable nginx.service
4. Restart the virtual machine to see if it has been set successfully.
Here, in order to show that the above can be set to boot successfully, A Fan checked the status of nginx just after the virtual machine started, and you can see that it is running.
Thank you for your reading, the above is the content of "how to build Nginx on CentOS7". After the study of this article, I believe you have a deeper understanding of how to build Nginx on CentOS7, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.