RedHat 7 Compiling and installing Nginx 1.12 and configuring the Web site

Source: Internet
Author: User
Tags install openssl openssl version

First, installation environment

1. Operating system version: Red Hat Enterprise Linux Server Release 7.2 (Maipo)

2, Nginx version: nginx-1.12.2.tar.gz

3, pcre version: pcre-8.42.tar.gz

4, zlib version: zlib-1.2.11.tar.gz

5. OpenSSL version: openssl-1.0.2l.tar.gz


Second, installation instructions

The official web-based dependency package for Nginx is described below:


Third, the installation process

1. Installing GCC:yum install gcc-c++-y


2. Compile and install Pcre

[[email protected] ~]# tar-zxf pcre-8.42.tar.gz[[email protected] ~]# CD Pcre-8.42[[email protected] pcre-8.42]#./config Ure[[email protected] pcre-8.42]# Make[[email protected] pcre-8.42]# make install

3, compile and install zlib: In fact, the system has been with the old version of the zlib-1.2.7 package, that should not uninstall it first? On the official website, the example does not mention that you want to uninstall the old version of the zlib, and compile the installation of the make install process we can see it is actually delete the original file, and then copy the new version of the file to the original path, that is, will replace the old version of the file, so I do not want to remove the old version.

[[email protected] ~]# tar-zxf zlib-1.2.11.tar.gz[[email protected] ~]# CD Zlib-1.2.11[[email protected] zlib-1.2.11]#. Configure[[email protected] zlib-1.2.11]# Make[[email protected] zlib-1.2.11]# make install

4, compile and install OpenSSL: In fact, the system has a openssl-1.0.1e package, but if you do not compile the new version of OpenSSL, will lead to the compilation of Nginx prompt can not find OpenSSL. The official website gives an example of compiling OpenSSL using the " ./configure darwin64-x86_64-cc--prefix=/usr" option, but I compile the install times wrong "Cc:error:x86_64:No Such file or directory", finally with"./config--prefix=/usr--shared "can also be found.

[[email protected] ~]# tar-zxf openssl-1.0.2l.tar.gz[[email protected] ~]# CD Openssl-1.0.2l[[email protected] Openssl-1 .0.2l]#./config--prefix=/usr--shared[[email protected] openssl-1.0.2l]# Make[[email protected] openssl-1.0.2l]# make Install

5, the creation of Nginx users, or after installing nginx will be error [Emerg] 35240#0:getpwnam ("Nginx") failed

6. Create the directory used in the compilation parameters Mkdir-p/var/tmp/nginx/client/, or after installing Nginx will be reported that the directory does not exist  

7. Compile and install Nginx

[[email protected] ~]# tar-zxf nginx-1.12.2.tar.gz[[email protected] ~]# CD Nginx-1.12.2[[email protected] nginx-1.12.2] #./configure--prefix=/usr/local/nginx--sbin-path=/usr/local/nginx/sbin/nginx--conf-path=/usr/local/nginx/conf/ nginx.conf--error-log-path=/var/log/nginx/error.log--http-log-path=/var/log/nginx/access.log--pid-path=/var/ Run/nginx/nginx.pid--lock-path=/var/lock/nginx.lock--user=nginx--group=nginx--with-http_ssl_module--with-http_ Stub_status_module--with-http_gzip_static_module--http-client-body-temp-path=/var/tmp/nginx/client/-- http-proxy-temp-path=/var/tmp/nginx/proxy/--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/--http-uwsgi-temp-path= /var/tmp/nginx/uwsgi--http-scgi-temp-path=/var/tmp/nginx/scgi--with-pcre

[[email protected] nginx-1.12.2]# make


[[email protected] nginx-1.12.2]# make install

8, use the command/usr/local/nginx/sbin/nginx-t to check the configuration file syntax, and command/usr/local/nginx/sbin/nginx to start Nginx

9. Use/usr/local/nginx/sbin/nginx-v to view the version

10, using browser access, successfully display the default site


Iv. Test Nginx startup script

1. Create the SH subdirectory under the Nginx directory to hold the startup script

[Email protected] ~]# mkdir /usr/local/nginx/sh[[email protected] ~]# vi  /usr/local/nginx/sh/nginx[[email protected] ~]# chmod +x /usr/local/nginx/sh/ Nginx[[email protected] ~]# cat /usr/local/nginx/sh/nginx#!/bin/bashng= "/usr/local/nginx/ Sbin/nginx "pidf="/var/run/nginx/nginx.pid "case " $ " in  start"      $NG  -t &> /dev/null    if [ $? -eq 0 ];then        $NG       echo  "nginx service  Start success. "     else      mkdir /var/run/nginx          $NG  -t &> /dev/null      if  [ $? -eq 0 ];then         $NG          echo  "Nginx service start success."       else         $NG  -t       fi    fi    ;;   stop)     kill -s QUIT  ' cat  $PIDF '      echo  "Nginx service stop success."      ;;   restart)     cat  $PIDF  &> /dev/null     if [ $? -eq 0 ];then    $0 stop     fi    $0 start    ;;   reload)      $NG  -t &> /dev/null    if  [ $? -eq 0 ];then      kill -s HUP  ' Cat   $PIDF '       echo  "Reload nginx config success."     else       $NG  -t    fi     ;;   *)     echo  "Usage: $0 {start|stop|restart|reload}"      exit esac

2, the startup script is soft-connected to the system environment variable path/usr/local/sbin, so that the execution of the script can be as easy as using the command

[Email protected] ~]# ln-s/usr/local/nginx/sh/nginx/usr/local/sbin/[[email protected] ~]# ll/usr/local/sbin/ Nginxlrwxrwxrwx 1 for root root 9 20:58/usr/local/sbin/nginx-/usr/local/nginx/sh/nginx

3. Test script, normal function

4. Add script to/etc/rc.d/rc.local to implement Nginx boot


V. Configuring the Web site

Nginx Profile Description: Nginx configuration file is divided into four parts: main (global setting), Server (host settings), upstream (Load balancer server settings) and location (URL matches the settings of a specific position). The instructions set in the main section affect all other settings, and the server part of the instruction is used primarily for specifying the host and port; the upstream instruction is primarily used for load balancing, setting up a series of back-end servers, and the Location section for matching page locations. The relationship between the four: the server Inherits Main,location inheritance Server,upstream neither inherits other settings nor inherits them. In each of these four sections, each part contains instructions that mainly contain Nginx's main module directives, Event module directives, HTTP Core module directives, and each section can also use other HTTP module directives, such as the HTTP SSL module, Httpgzip static modules and HTTP addition modules.

The configuration Web site is primarily used in the server and location sections.

1. Add a virtual host in/usr/local/nginx/conf/nginx.conf and create a home file under/usr/local/nginx/www index.html

2,reload a bit nginx, and do the hosts analysis

3, test access to the virtual host www.jianlong.com, access to normal

4, for the above virtual host set alias, and then reload the Nginx, and for the alias Www.jl.com to do the hosts analysis

5. Test access using aliases, Access normal

6, configure redirect Jump, and then add a virtual host, reload, do a good job after the hosts to visit jianlong.com will automatically jump to www.jianlong.com, configured as follows:

The effect is as follows (please click to view GIF image)

Http://i2.51cto.com/images/blog/201804/20/549cefe66943fd262e408b91503bf84b.gif

This article is from Jiangjianrong's technical blog, if reproduced please indicate the source http://blog.51cto.com/jiangjianlong/2105585

RedHat 7 Compiling and installing Nginx 1.12 and configuring the Web site

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.