Nginx Server Installation and configuration
1. Install the PCRE package
[Email protected] ~]# Rpm-qa | grep pcre
[Email protected] ~]# yum-y install Pcre
2. Create Nginx User
[Email protected] ~]# useradd-s/sbin/nologin nginx
[Email protected] ~]# passwd nginx
Changing password for user nginx.
New Password:
Bad password:it are too short
Bad Password:is too simple
Retype new Password:
Passwd:all authentication tokens updated successfully.
3, nginx compilation parameters
--user specify the user to which the initiator belongs
--group Specifying groups
--prefix Specifying the installation path
--sbin-path set the path name of the Nginx binary file
--conf-path specifying the configuration file path
--error-log-path Error log file path
--http-log-path specifying access log file path
--http-client-body-temp-path setting the temporary file path for storing HTTP client request principals
--http-proxy-temp-path setting the path to store HTTP proxy temporary files
--http-fastcgi-temp-path setting the path to a temporary file that stores HTTP fastcgi
--pid-path Setting the Nginx.pid file path
--lock-path Setting the Nginx.lock file path
--WITH-OPENSSL Enable SSL
--with-pcre Enable regular expressions
--with-http_stub_status_module installing modules that can monitor nginx status
--with-http_ssl_module Enable SSL Support
--with-http_gzip_static_module Enable gzip compression
4. Installing Nginx
[Email protected] nginx-1.9.6]#/configure \
>--user=nginx \
>--group=nginx \
>--prefix=/usr/local/nginx \
>--sbin-path=/usr/sbin/nginx \
>--conf-path=/etc/nginx/nginx.conf \
>--error-log-path=/var/log/nginx/error.log \
>--http-log-path=/var/log/nginx/access.log \
>--http-client-body-temp-path=/tmp/nginx/client_body \
>--http-proxy-temp-path=/tmp/nginx/proxy \
>--http-fastcgi-temp-path=/tmp/nginx/fastcgi \
>--pid-path=/var/run/nginx.pid \
>--lock-path=/var/lock/subsys/nginx \
>--with-http_stub_status_module \
>--with-http_ssl_module \
>--with-http_gzip_static_module \
>--with-pcre \
>--with-http_realip_module \
>--with-http_sub_module
[[email protected] nginx-1.9.6]# make && make install
[Email protected] nginx-1.9.6]# ls/usr/local/nginx/
Html
Check Configuration
[Email protected] nginx-1.9.6]# nginx-t
Nginx:the configuration file/etc/nginx/nginx.conf syntax is OK
Nginx: [Emerg] mkdir () "/tmp/nginx/client_body" failed (2:no such file or directory)
Nginx:configuration file/etc/nginx/nginx.conf Test Failed
[Email protected] nginx-1.9.6]# mkdir/tmp/nginx/client_body-p
[Email protected] nginx-1.9.6]# nginx-t
Nginx:the configuration file/etc/nginx/nginx.conf syntax is OK
Nginx:configuration file/etc/nginx/nginx.conf Test is successful
Start Nginx
[Email protected] nginx-1.9.6]# Nginx
[Email protected] nginx-1.9.6]# NETSTAT-TLNP |grep nginx
TCP 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4554/nginx
5. View Nginx version and compile parameters
[Email protected] nginx-1.9.6]# nginx-v
Nginx version:nginx/1.9.6
Built by GCC 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
Built with OpenSSL 1.0.1e-fips 2013
TLS SNI Support Enabled
Configure arguments:--user=nginx--group=nginx--prefix=/usr/local/nginx--sbin-path=/usr/sbin/nginx--conf-path=/ etc/nginx/nginx.conf--error-log-path=/var/log/nginx/error.log--http-log-path=/var/log/nginx/access.log-- Http-client-body-temp-path=/tmp/nginx/client_body--http-proxy-temp-path=/tmp/nginx/proxy-- http-fastcgi-temp-path=/tmp/nginx/fastcgi--pid-path=/var/run/nginx.pid--lock-path=/var/lock/subsys/nginx-- With-http_stub_status_module--with-http_ssl_module--with-http_gzip_static_module--with-pcre--with-http_realip_ Module--with-http_sub_module
6. Control Nginx Server
Start: Nginx
Stop: Nginx-s stop
Exit: Nginx-s quit
Reopen: Nginx-s Reopen
Reload configuration: Nginx-s Reload
7. Configure Nginx Startup script
[Email protected] ~]# Vim/etc/init.d/nginx
#!/bin/bash
# Chkconfig:-30 21
# Description:http Service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
Nginx_sbin= "/usr/sbin/nginx"
nginx_conf= "/etc/nginx/nginx.conf"
Nginx_pid= "/var/run/nginx.pid"
Retval=0
Prog= "Nginx"
#Source Networking Configuration
. /etc/sysconfig/network
# Check Networking is up
[${networking} = "No"] && exit 0
[-X $NGINX _sbin] | | Exit 0
Start () {
Echo-n $ "Starting $prog:"
Touch/var/lock/subsys/nginx
Daemon $NGINX _sbin-c $NGINX _conf
Retval=$?
Echo
Return $RETVAL
}
Stop () {
Echo-n $ "Stopping $prog:"
Killproc-p $NGINX _pid $NGINX _sbin-term
Rm-rf/var/lock/subsys/nginx/var/run/nginx.pid
Retval=$?
Echo
Return $RETVAL
}
Reload () {
Echo-n $ "Reloading $prog:"
Killproc-p $NGINX _pid $NGINX _sbin-hup
Retval=$?
Echo
Return $RETVAL
}
Restart () {
Stop
Start
}
Configtest () {
$NGINX _sbin-c $NGINX _conf-t
return 0
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Reload
Reload
;;
Restart
Restart
;;
Configtest)
Configtest
;;
*)
echo $ "Usage: $ {start|stop|reload|restart|configtest}"
Retval=1
Esac
Exit $RETVAL
Set executable permissions
[Email protected] ~]# chmod 755/etc/init.d/nginx
Add Boot Boot
[Email protected] ~]# chkconfig--add nginx
[[email protected] ~]# chkconfig nginx on
Open
[[Email protected] ~]# service Nginx start
Starting Nginx: [OK]
Stop it
[[Email protected] ~]# service Nginx stop
stopping Nginx: [OK]
Restart
[[Email protected] ~]# service Nginx restart
stopping Nginx: [OK]
Starting Nginx: [OK]
Reload Configuration
[[Email protected] ~]# service Nginx Reload
Reloading Nginx: [OK]
8, configure the Nginx server PHP parsing
[Email protected] nginx-1.9.6]# vim/etc/nginx/nginx.conf
To open the PHP configuration:
65 Location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param Script_ filename /usr/local/nginx/html$fastcgi_script_name;
70 include Fastcgi_params;
71 }
User Nginx;
Worker_processes 8;
Error_log/var/log/nginx/error.log;
Pid/var/run/nginx.pid;
Events {
Worker_connections 204800;
}
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/var/log/nginx/access.log main;
Sendfile on;
Tcp_nopush on;
CharSet Utf-8;
650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/78/49/wKiom1Z5TM-iS_xQAAB0MHM1BR4922.jpg "title=" 1.jpg " alt= "Wkiom1z5tm-is_xqaab0mhm1br4922.jpg"/>
PHP-FPM Start Error
Starting PHP-FPM [18-dec-2015 13:33:03] error:unable to bind listening sockets for address ' 127.0.0.1:9000 ': Address Alrea DY in use (98)
[18-dec-2015 13:33:03] ERROR:FPM initialization failed
Failed
[Email protected] nginx-1.9.6]#/usr/local/php/sbin/php-fpm-t
[18-dec-2015 13:35:14] Notice:configuration file/usr/local/php/etc/php-fpm.conf Test is successful
[Email protected] nginx-1.9.6]# Killall PHP-FPM
[[Email protected] nginx-1.9.6]# service PHP-FPM start
Starting php-fpm Done
Reload Configuration
[Email protected] nginx-1.9.6]# nginx-t
Nginx:the configuration file/etc/nginx/nginx.conf syntax is OK
Nginx:configuration file/etc/nginx/nginx.conf Test is successful
[Email protected] nginx-1.9.6]# Nginx-s Reload
Test PHP parsing
[Email protected] nginx-1.9.6]# vim/usr/local/nginx/html/index.php
<?php
Phpinfo ();
?>
650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/78/48/wKioL1Z5Us-w4n_RAAFOnfSzyw4757.jpg "title=" 2.jpg " alt= "Wkiol1z5us-w4n_raafonfszyw4757.jpg"/>
1.8LNMP Environment Installation Nginx