Nginx Series -1.linux Installation Nginx

Source: Internet
Author: User
Tags openssl nginx server nginx reverse proxy

Nginx Series -1.linux Installation Nginx catalogue-Nginx Series

Nginx Series -1.linux installation Nginx
Nginx Series-2. Configuring the Lnmp (Linux, Nginx, MySQL, PHP) architecture
Nginx Series-3. Configuring Nginx Virtual Host
Nginx Series -4.nginx log configuration and log cutting
Nginx Series-5. Configure the Nginx anti-theft chain
Nginx Series-6. Configuring Nginx HTTPS
Nginx Series-7. Configuring Nginx using UWSGI support web.py framework
Nginx Series-8. Configuration nginx+apache for dynamic and static separation
Nginx Series-9. Configuring NFS for static and dynamic separation of Nginx
Nginx Series-10. Using Nginx to build forward proxy service
Nginx Series-11. Configuring Nginx Reverse proxy and load balancing

Experimental Environment
A minimized CentOS 7.3 virtual machine

A. Source mode installation Nginx One, installation Nginx
    1. Installing Nginx Dependency Packages

      yum install -y pcre-devel zlib-devel openssl-devel wget gcc tree vim

      Nginx relies on Pcre, zlib, OpenSSL, if there is a problem when configuring before compiling
      Three packages can be installed using Yum (Pcre-devel, Zlib-devel, Openssl-devel)

    2. Download Nginx Source package from Nginx official website

      wget http://nginx.org/download/nginx-1.12.2.tar.gz

    3. Extract the Nginx source package to /root/nginx , and view Nginx file structure

      tar -xzvf nginx-1.12.2.tar.gz

    4. /root/nginxConfiguring pre-compilation in a directory

      cd /root/nginx*./configure --prefix=/usr/local/nginx --with-http_ssl_module

    5. To /root/nginx perform a compilation installation in a directory
      make && make install

Second, start Nginx
    1. Go to the installation directory to /usr/local/nginx view the directory structure

      cd /usr/local/nginxpwdls

    2. Start Nginx

      /usr/local/nginx/sbin/nginx
    3. To see if the Nginx process is started

      ps aux | grep nginx

    4. View the port numbers that Nginx occupies

      netstat -tlnp

    5. Use a local host to access the Nginx server on the virtual machine

      If you cannot access nginx from localhost, check your virtual machine firewall configuration
      CentOS off SELinux ( setenforce 0 )
      centos6.x shutting down the firewall ( service iptables stop )
      centos7.x shutting down the firewall ( systemctl stop firewalld )

Third, stop Nginx

Three ways to stop Nginx

# 1. 立即停止Nginx服务/usr/local/nginx/sbin/nginx -s stop# 2.完成当前任务后停止/usr/local/nginx/sbin/nginx -s quit# 3.杀死Nginx进程killall nginx
Iv. adding Nginx commands to environment variables
    1. Use soft links to nginx link to/usr/local/sbin

      ln -s /usr/local/nginx/sbin/nginx /usr/local/sbinll /usr/local/sbin/ | grep "nginx"

    2. Show Current environment variablesPATH

      echo $PATH
    3. Edit .bash_profile File

      vim ~/.bash_profile

      Add the following to the end of the .bash_profile file

      export PATH=$PATH:/usr/local/nginx/sbin

    4. Reference .bash_profile File

      source ~/.bash_profile
    5. Using nginx commands
      # 启动nginxnginx# 停止nginxnginx -s quit
Five, add nginx to the system service
    • Create and edit files/root/service-nginx.sh
#!/bin/sh## filename:service-nginx.sh## nginx-this script starts and stops the Nginx daemon## chkconfig:-15# des Cription:nginx is an HTTP (s) server, HTTP (s) reverse # Proxy and IMAP/POP3 proxy server# Processname:ngin  x# 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 are up. ["$NETWORKING" = "no"] && exit 0nginx= "/usr/sbin/nginx" prog=$ (basename $nginx) #NGINX_CONF_FILE = "/etc/nginx/ Nginx.conf "nginx_conf_file="/usr/local/nginx/conf/nginx.conf "[-f/etc/sysconfig/nginx] &&. /etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_dirs () {# Make required directories user= ' $nginx-v 2>&amp ; 1 | grep "Configure Arguments:.*--user=" | Sed ' s/[^*]*--user=\ ([^]*\). */\1/g '-' if [-N ' $user "]; Then if [-Z ' grep $user/etc/passwd ']; Then USEradd-m-s/bin/nologin $user fi options= ' $nginx-v 2>&1 | grep ' Configure arguments: ' for opt in $options; do if [' Echo $opt | grep '. *-temp-path ']; Then value= ' echo $opt | Cut-d "="-F 2 ' if [!-D "$value"];              Then # echo "Creating" $value mkdir-p $value && chown-r $user $value     fi fi Done Fi}start () {[-X $nginx] | | Exit 5 [-F $NGINX _conf_file] | | Exit 6 MAKE_DIRS    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}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 "$" in start) Rh_status_q && exit 0 $    ;; Stop) rh_status_q | |    Exit 0 $;;    Restart|configtest) \ n; Reload) Rh_status_q | |    Exit 7 $;;    Force-reload) force_reload;;    status) Rh_status;; Condrestart|try-restart) rh_status_q | |    Exit 0;;  *) echo $ "Usage: $ start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2esac# END
    1. With the /root/service-nginx.sh replacement/etc/init.d/nginx

      mv /root/service-nginx.sh /etc/init.d/nginx
    2. Give executable limits

      chmod 755 /etc/init.d/nginx
    3. Perform
      systemctl start nginx
Six, source mode installation Nginx, automated installation script
#!/bin/bash# installation configurationNGINX_VERSION=1.12.2NGINX_SRC_PATH=/rootNGINX_BIN_PATH=/usr/local/nginx# disable firewallsystemctl stop firewalldsetenforce 0# installation dependenceyum install -y pcre-devel zlib-devel openssl-devel wget gcc# download nginx source packagecd ${NGINX_SRC_PATH}wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz# unzip source packagetar -xzvf nginx-${NGINX_VERSION}.tar.gzcd ./nginx-${NGINX_VERSION}# install nginx./configure --prefix=${NGINX_BIN_PATH} --with-http_ssl_modulemake & make install# start nginx servicecd ${NGINX_BIN_PATH}/sbin./nginx# END
B. Yum-style installation Nginx
    1. Installing Epel

      yum install epel-* -y
    2. Installing Nginx
      yum install -y nginx

Nginx Series -1.linux Installation Nginx

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.