Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx installation

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Installation method of yum:

1 、 yum info nginx

2 、 yum install nginx

3 、 service nginx start

4 、 service nginx restart

Second, manual installation:

Nginx can be installed using the default package for each platform. This article introduces the use of source code compilation and installation, including specific compilation parameter information. Before the official start, the compilation environment gcc gaming + development library and so on need to be installed in advance, here you have installed by default.

The following instructions can be used in the ububtu platform compilation environment:

# apt-get install build-essential

# apt-get install libtool

The centos platform compilation environment uses the following instructions

Install make:

# yum-y install gcc automake autoconf libtool make

Install the galleys:

# yum install gcc gcc-c++

Generally speaking, we need to install pcre and zlib first, the former for rewriting rewrite and the latter for gzip compression.

It can be any directory. / usr/local/src is selected for this article.

# cd / usr/local/src

Install the ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ library to download the latest PCRE source package, download, compile and install the PCRE package using the following command: (http://www.pcre.org/)

# cd / usr/local/src

Wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz

# tar-zxvf pcre-8.39.tar.gz

# cd pcre-8.39

#. / configure & & make & & make install

Install the zlib library http://zlib.net/zlib-1.2.8.tar.gz to download the latest zlib source package, download, compile and install the zlib package using the following command:

# cd / usr/local/src

# wget http://zlib.net/zlib-1.2.8.tar.gz

# tar-zxvf zlib-1.2.8.tar.gz

Cd zlib-1.2.8

#. / configure & & make & & make install

Install ssl (some vps does not have ssl installed by default)

# cd / usr/local/src

# wget http://www.openssl.org/source/openssl-1.0.2h.tar.gz

# tar-zxvf openssl-1.0.2h.tar.gz

Install nginx

There are generally two versions of Nginx, stable version and development version. You can choose one of these two versions according to your purpose. Here are the detailed steps for installing Nginx into the / usr/local/nginx directory:

# cd / usr/local/src

# wget http://nginx.org/download/nginx-1.8.1.tar.gz

# tar-zxvf nginx-1.8.1.tar.gz

Cd nginx-1.8.1

#. / configure-sbin-path=/usr/local/nginx/nginx-conf-path=/usr/local/nginx/nginx.conf-pid-path=/usr/local/nginx/nginx.pid-with-http_ssl_module-with-pcre=/usr/local/src/pcre-8.39-with-zlib=/usr/local/src/zlib-1.2.8-with-openssl=/usr/local/src/openssl-1.0.2h

# make & & make install

#-with-pcre=/usr/src/pcre-8.34 refers to the source code path of pcre-8.34. #-with-zlib=/usr/src/zlib-1.2.7 refers to the source code path of zlib-1.2.7.

After successful installation, the / usr/local/nginx directory is as follows

Fastcgi.conf koi-win nginx.conf.default fastcgi.conf.default logs scgi_params fastcgi_params mime.types scgi_params.default fastcgi_params.default mime.types.default uwsgi_params html nginx uwsgi_params.default koi-utf nginx.conf win-utf

Boot to ensure that port 80 of the system is not occupied by other programs, run the / usr/local/nginx/nginx command to start Nginx

# netstat-ano | grep 80

If the result is not found, ignore this step (under ubuntu, you must start with sudo, otherwise you can only run it in the foreground)

# sudo / usr/local/nginx/nginx

Open a browser to access the IP of this machine, if the browser appears Welcome to nginx! Indicates that Nginx is installed and running successfully.

At this point, the installation of nginx is complete. If you only deal with static html, you don't have to continue the installation.

If you need to deal with php scripts, you also need to install php-fpm.

-

1. Write a script named nginx in the / etc/init.d/ directory

#! / 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

2. Nginx starts, stops, and uninterrupted service restarts

[root@example ~] # cp nginx / etc/init.d/

[root@example ~] # chmod 755 / etc/init.d/nginx

[root@example] # chkconfig-- add nginx

[root@example ~] # service nginx start

[root@example ~] # service nginx stop

[root@example ~] # service nginx reload

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report