In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to install Nginx in Linux and what matters needing attention". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to install Nginx in Linux and what matters needing attention" can help you solve the problem.
A brief description of 1.nginx
A. Nginx is a high-performance http and reverse proxy server, is also an imap/pop3/smtp server, the purpose of the initial development is to proxy e-mail server roommate: igor sysoev development, the source code is in line with bsd open source. Its characteristic is that it occupies less memory and has strong concurrency ability. There are many large websites using nginx in China: Baidu, Taobao, Tencent and so on.
As a http server, b.nginx has the following basic characteristics:
B.1 handle static files, index files, and automatic indexing, and turn on file descriptor buffering.
B.2 reverse proxy acceleration without caching, simple load balancing and fault tolerance
B.3 modular structure, including filter such as gzipping,byte ranges,chunked responses and ssi-filter, if multiple ssi present in egg liquid are processed by fastcgi or other proxy servers, the process can be run in parallel without waiting for each other.
B.4 supports ssl and tlssni.
two。 Preparatory work
a. The above is a brief introduction to nginx, if you want to know more about nginx, please learn by yourself through the network.
b. If you want to do a good job, you must first sharpen its tools, so let's simply install niginx under linux. Some problems are needed in the installation process, and synchronization will be mentioned in the blog.
The installation of c.nginx depends on the following three packages, which means the three packages that must be installed before installing nginx, in the order I wrote:
C.1 openssl library is required for ssl function, download address:
C.2 zlib library is required for gzip module, download address:
C. 3 pcre library is required for rewrite module. Download address:
The installation package for d.nginx can be downloaded from:
e. Upload all the downloaded software above to the linux system using xftp. The upload path and software are shown in the figure:
f. The software and systems required for operation are as follows: virtual machine (vmware), centos system installed in the virtual machine, xshell,xftp, and several packages above.
g. Let's start installing the software in the order described above.
3. The openssl library and the zlib library required by the gzip module are required to install the ssl function
A (1). First of all, we install the openssl library plug-in required by the ssl feature. Note: the installation process is installed according to the file path I set under linux. The command is as follows:
A.1 tar-zxvf soft/openssl-snap-20160104
A.2 cd cd openssl-snap-20160104/
A.3. / config
A.4 make
A.5 make install
B (1). Installing the gzip module requires the zlib library to be installed in exactly the same way as openssl, which is divided into the above five steps, except that the name of the file is different, and the command is simple as follows:
B.1 tar-zxvf soft/openssl-snap-20160104
B.2 cd openssl-snap-20160104/
B.3. / configure
B.4 make
B.5 make install
b. If no error is reported, the installation is complete.
4. Pcre library is required to install rewrite module
a. Installing the rewrite module requires the pcre library to be installed in exactly the same way as openssl, which is divided into the above five steps, except that the name of the file is different, and the command is simple as follows:
A.1 tar-zxvf soft/pcre-8.38.tar.gz
A.2 cd pcre-8.38/
A.3. / configure
A.4 make
A.5 make install
b. An error occurred during the execution of. / configure, so that the execution could not continue. The error message is as follows:
Error: you need a C++ compiler for C++ support. Seeing this sentence, we have already guessed that it should be C++ package information, but it is not in linux, so you can install this package information first. The installation command is:
Yum install-y gcc gcc-c++
c. After installing the above C++ package, run it here and find that the message shows that the installation is successful, and when all the installation based on the above is complete, you need to install the nginx service.
5. Install the nginx service
a. Installing the rewrite module requires the pcre library to be installed in exactly the same way as openssl, which is divided into the above five steps, except that the name of the file is different, and the command is simple as follows:
A.1 tar-zxvf soft/nginx-1.9.9.tar.gz
A.2 cd nginx-1.9.9/
A.3. / configure-with-pcre=../pcre-8.38/-with-zlib=../zlib-1.2.8/-with-openssl=../openssl-snap-20160104/
A.4 make
A.5 make install
b. An error occurred during the execution of. / configure, so that the execution could not continue. The error message is as follows:
Error: you need a C++ compiler for C++ support. Seeing this sentence, we have already guessed that it should be C++ package information, but it is not in linux, so you can install this package information first. The installation command is:
Yum install-y gcc gcc-c++
c. After installing the above C++ package, run it here and find that the message shows that the installation is successful. Blog post here if there is no error during the installation, it means that the installation has been successful, here is to test whether the installation of nginx is successful.
6. Monitor whether nginx is installed successfully
a. When all the above steps are completed, it means that the nginx installation is complete, so how do we determine if the installation is successful? Use the following command to determine.
A.1 cd / usr/local/nginx/sbin/
A.2. / nginx-t
b. I made an error when I executed the second command (. / nginx-t) and reported an error with no permissions. As shown in the figure:
Note: according to the error prompt, we can see that there is no permission under / usr/local/nginx, and the solution is very simple, we assign value permissions to the file.
c. As shown in the following figure, after configuring the permissions (the configuration permissions need to be switched to the root user), perform the above two steps. If the linux is as shown in the following figure, the installation is successful.
d. After confirming that the installation is complete, you first need to launch and check the default installation port of nginx. The two commands are as follows:
(1). / nginx
(2) netstat-ntlp, the default port of nginx is 80
e. Open port 80 to make it accessible to the external environment (if port 80 is not open, it cannot be accessed by the external environment). The command and screenshot are as follows:
Vim / etc/sysconfig/iptables
Note: here, after I use vim to change the fire strength information, an error occurs when restarting the firewall. The error message is: try `iptables-restore-h' or 'iptables-restore-- help' for more information. This error message indicates that we cannot restart the firewall. What should I do? I tested the way the command was written to change it, and found that the change was successful, as shown in the figure:
f. When the above work is done, we browse in an external browser: http://ip, which appears as shown in the figure, indicating that the installation is complete.
7. Set nginx to boot automatically
a. When the above 6 steps are completed, the installation has been completely successful, but one of the problems we face every time we boot is to execute the command (1: cd / usr/local/nginx/sbin/ 2:./nginx-t). If this is necessary, set the command to boot automatically as follows: add the startup command of nginx to / etc/rc.local:
Echo "/ usr/local/nginx/sbin/nginx-c / usr/local/nginx/conf/nginx.conf" > > / etc/rc.local
b. Then shut down the linux and restart it for testing. If the http://ip is still accessible, the configuration is successful. I have tested it, and the configuration is completely successful.
8. Start the nginx service using the server command
a. Now feel that the startup command is too troublesome, although boot can be self-booting, but every change to restart nginx, either enter the command or boot, it is not very good, so can we create a better way? Of course, we can set up the system v script.
b. The script code is as follows:
#! / bin/sh # # nginx-this script starts and stops the nginx daemon # chkconfig:-85 15 # description: nginx is an http (s) server, http (s) reverse\ # proxy and imap/pop3 proxy server # processname: nginx # config: / etc/nginx/nginx.conf # config: / etc/sysconfig/nginx # pidfile: / var/run/nginx.pid # source function library. . / etc/rc.d/init.d/functions # source networking configuration. . / etc/sysconfig/network # check that networking is up. ["$networking" = "no"] & & exit 0 nginx= "/ usr/local/nginx/sbin/nginx" prog=$ (basename $nginx) nginx_conf_file= "/ usr/local/nginx/conf/nginx.conf" [- f / etc/sysconfig/nginx] & &. / etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start () {[- x $nginx] | | exit 5 [- f $nginx_conf_file] | | exit 6 echo-n $"starting $prog:" daemon $nginx-c $nginx_conf_file retval=$? Echo [$retval-eq 0] & & touch $lockfile return $retval} stop () {echo-n $"stopping $prog:" killproc $prog-quit retval=$? Echo [$retval-eq 0] & & rm-f $lockfile return $retval killall-9 nginx} restart () {configtest | | return $? Stop sleep 1 start} reload () {configtest | | return $? Echo-n $"reloading $prog:" killproc $nginx-hup retval=$? Echo} force_reload () {restart} configtest () {$nginx-t-c $nginx_conf_file} rh_status () {status $prog} rh_status_q () {rh_status > / dev/null 2 > & 1} case "$1" in start) rh_status_q & & exit 0 $1; stop) rh_status_q | | exit 0 $1;; restart | configtest) $1 Reload) rh_status_q | | exit 7 $1;; force-reload) force_reload;; status) rh_status;; condrestart | try-restart) rh_status_q | | exit 0;; *) echo $"usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest}" exit 2 esac
c. The creation command is as follows. First jump to / etc/init.d to create the nginx startup script file. The command is as follows
C.1 cd / etc/init.d/
C.2 vim nginx create a new nginx file, copy the above command code into it, and then save it
d. Modify script permissions with the following command: chmod 755 nginx
e. Add script files to chkconfig chkconfig-- add nginx
f. Set nginx boot to automatically start chkconfig at levels 3 and 5-- level 35 nginx on
g. Test whether the nginx script file can be used properly, the command is as follows, I have tested, all can be used.
G.1 / etc/init.d/nginx restart
G.2 / etc/init.d/nginx reload
G.3 / etc/init.d/nginx stop
This is the end of the content about "how to install Nginx in Linux and what matters needing attention". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.