April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Red Hat Enterprise Linux installation at 7.3 Nginx

Red Hat Enterprise Linux installation at 7.3 Nginx

I. Introduction

Nginx ( “engine x”) is a by Russian designer Igor Sysoev procedures developed high-performance Web server and reverse proxy, also a IMAP / POP3 / SMTP proxy server. In the case of high concurrent connections, Nginx Apache server is a good substitute.

Second, prepare

1, environment

Platform: Red Hat Enterprise Linux Server Release 7.3 (Maipo)

3.10.0-514.el7.x86_64

2, install build tools and libraries

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

3, install pcre

PCRE role is to support Ngnix Rewrite function.

Check whether the installation pcre

# pcre-config –version

bove indicate that you have installed.

If not installed, with reference to the following steps:

1) Download

https://sourceforge.net/projects/pcre/files/pcre/

2) extracting installation package:
# PCRE zxvf the tar-8.35.tar.gz

3) compile and install
# cd pcre-8.35

# ./configure

# make && make install

Third, the installation

1, download the installation package nginx

http://nginx.org/download/

2, extract

# tar zxvf nginx-1.10.2.tar.gz

3. Compile

# ./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-pcre

4, installation

# make

# make install

5, test

View nginx version

# /usr/local/nginx/sbin/nginx -v

Displays version information, proof has been successfully installed

Fourth, the configuration

1. Create a user

Nginx create run-use user ruready:
# / usr / sbin / groupadd ruready
# / usr / sbin / useradd -g ruready ruready

2???nginx.conf

# vi /usr/local/nginx/conf/nginx.conf

user ruready ruready;
worker_processes 2;

error_log /usr/local/nginx/logs/error.log crit; # ?????????
pid /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}

http {
include mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

access_log /usr/local/nginx/logs/access.log main;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;

# server
server {
listen 80;
server_name localhost;

charset utf-8;

access_log /usr/local/nginx/logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}

error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
# deny all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}

# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

3, check the correctness of the configuration file ngnix.conf

# /usr/local/nginx/sbin/nginx -t

Fifth, start

1, the start command

# /usr/local/nginx/sbin/nginx

3, can be tested through command links

links 127.0.0.1:8080

Six commonly used commands

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/sbin/nginx/nginx.conf # ??????????

/ Usr / local / nginx / sbin / nginx -s reload # reload the configuration file

/usr/local/nginx/sbin/nginx -s reopen # ?? Nginx

/usr/local/nginx/sbin/nginx -s stop # ?? Nginx

Seven other

1, set the boot

echo “/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf” >> /etc/rc.local

2, added to the service Service

touch /etc/init.d/nginx

chmod 755 nginx // modify the script file permissions nginx

chkconfig –add nginx // The script file is added in chkconfig

chkconfig –level 35 nginx on // set nginx at startup in level 3 and 5

nginx document reads 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

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>