Compile the installation Nginx and modify the version header information

Source: Internet
Author: User

Today to do experiments, think of my Yum installed Nginx+php-fpm+mysql server on the Nginx version is a little low, and also add two 3rd party module, go to the Nginx official website to download the latest stable version of nginx-1.0.6, well, nonsense not to say to see the tutorial bar .
System version: CentOS 5.6
ip:192.168.1.200
Required Packages: nginx-1.0.6.tar.gz nginx-accesskey-2.0.3.tar.gz ngx_cache_purge-1.3.tar.gz (these 3 packages can be downloaded on their own, I will not provide it)

1. Unzip and modify the Nginx kernel
Tar zxf nginx-1.0.6.tar.gz && tar zxf nginx-accesskey-2.0.3.tar.gz && tar zxf Nginx-accesskey-2.0.3.tar.gz
CD nginx-1.0.6
VI src/http/ngx_http_header_filter_module.c
Modify the ngx_http_header_filter_module.c in the
static char ngx_http_server_string[] = "Server:nginx" CRLF;
static char ngx_http_server_full_string[] = "server:" Nginx_ver CRLF;
Change to:
static char ngx_http_server_string[] = "Server:tws" CRLF;
static char ngx_http_server_full_string[] = "server:" Nginx_ver CRLF; (This line do not change, or the subsequent compilation will be error, I do not know how the other people on the Internet to deal with, do not know whether they have personally tried)

Again
VI src/core/nginx.h


Switch


2. Start compiling and installing Nginx and 3rd party modules
./configure--user=nginx--group=nginx--add-module=. /ngx_cache_purge-1.3--add-module=. /nginx-accesskey-2.0.3--prefix=/usr/share/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=/ Var/lib/nginx/tmp/client_body--http-proxy-temp-path=/var/lib/nginx/tmp/proxy--http-fastcgi-temp-path=/var/lib/ nginx/tmp/fastcgi--pid-path=/var/run/nginx.pid--lock-path=/var/lock/subsys/nginx--with-http_secure_link_module --with-http_random_index_module--with-http_ssl_module--with-http_realip_module--with-http_addition_module-- With-http_sub_module--with-http_dav_module--with-http_flv_module--with-http_gzip_static_module--with-http_stub _status_module--with-http_perl_module--with-http_geoip_module--with-mail--with-mail_ssl_module
This is my compilation parameters, of course, you can according to your own needs to modify.

If there is an error in compiling the installation, you will need to execute the following statement
Yum-y Install Pcre-devel geoip* openssl-devel

Configure after the completion of the error, the implementation
Make && Meke Install
View Nginx version number and compile parameters after installation

I don't have the following compile parameters here, you know.

3. Enable Nginx to boot with the system
Cd/etc/rc.d/init.d
VI Nginx
Nginx's content:

#!/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 are up.
["$NETWORKING" = "no"] && exit 0

nginx= "/usr/sbin/nginx"
prog=$ (basename $nginx)

Nginx_conf_file= "/etc/nginx/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-term
Retval=$?
If [$retval-eq 0]; Then
If ["$CONSOLETYPE"! = "Serial"]; Then
Echo-en "\\033[16g"
Fi
While Rh_status_q
Do
Sleep 1
Echo-n $ "."
Done
Rm-f $lockfile
Fi
Echo
Return $retval
}

Restart () {
Configtest | | Return $?
Stop
Start
}

Reload () {
Configtest | | Return $?
Echo-n $ "Reloading $prog:"
Killproc $nginx-hup
Sleep 1
Retval=$?
Echo
}

Configtest () {
$nginx-T-C $NGINX _conf_file
}

Rh_status () {
Status $prog
}

Rh_status_q () {
Rh_status >/dev/null 2>&1
}

# Upgrade The binary with no downtime.
Upgrade () {
Local pidfile= "/var/run/${prog}.pid"
Local oldbin_pidfile= "${pidfile}.oldbin"

Configtest | | Return $?
Echo-n $ "Staring new master $prog:"
Killproc $nginx-USR2
Sleep 1
Retval=$?
Echo
if [[-F ${oldbin_pidfile} &&-F ${pidfile}]; Then
Echo-n $ "Graceful shutdown of old $prog:"
Killproc-p ${oldbin_pidfile}-term
Sleep 1
Retval=$?
Echo
return 0
Else
echo $ "Something bad happened, manual intervention required, maybe restart?"
Return 1
Fi
}

Case "$" in
Start
Rh_status_q && Exit 0
$
;;
Stop
Rh_status_q | | Exit 0
$
;;
Restart|configtest)
$
;;
Force-reload|upgrade)
Rh_status_q | | Exit 7
Upgrade
;;
Reload
Rh_status_q | | Exit 7
$
;;
STATUS|STATUS_Q)
Rh_$1
;;
Condrestart|try-restart)
Rh_status_q | | Exit 7
Restart
;;
*)
echo $ "Usage: $ {Start|stop|reload|configtest|status|force-reload|upgrade|restart}"
Exit 2
Esac


And then execute
chmod a+x Nginx
Chkconfig--add Nginx
Chkconfig Nginx on
Service Nginx Start

Final execution
Curl-i http://localhost

Can see Nginx normal operation, well, the next is to modify the nginx.conf, I will not say.

Compile the installation Nginx and modify the version header information

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.