Nginx + php-fpm source compiler

Build Nginx WEB server

Nginx and the kernel module, wherein the core is very small and compact design, the work done is very simple, only by searching the configuration file to map the client requests a location block (location Nginx instruction is a configuration for URL match), and each disposed in this location instruction will start in different modules to do the work.

Apache Nginx advantages with respect to:

1, high concurrency response performance is very good, the official static files Nginx concurrent 5w / s

2, reverse proxy performance is very good. (It can be used for load balancing)

3, memory and CPU occupancy rate is low. (The Apache 1 / 5-1 / 10)

4, features a more Apache less (both common features)

5, may be used for php cgi mode and manner fastCGI

The installation must rely

yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel 

gcc is an abbreviation for GNU Compiler Collection, you can compile C and C ++ source code, etc., it is the development of GNU C and C ++ and other languages very compiler (the earliest time can only compile C, then quickly evolved into a multi-compiler set of languages, such as Fortran, Pascal, Objective-C, Java, Ada, Go , etc.)
  stage gcc compile C ++ source code, can only compile C ++ source files, and library link can not automatically and C ++ programs use (compiled process is divided into compile, link two stages, and be careful not to confuse the concept of executable files, executable files relatively speaking there are three important concepts: the compiler (compile), links (link), load (load) source files are compiled into object files, object files, along with multiple library is linked into a final executable file, the executable file is loaded into memory to run). Therefore, commonly used command g ++ to compile C ++ programs and connection, the program will automatically call gcc compiler achieved.
  gcc-c ++ C source code can be compiled, but it will as the C ++ source code, the suffix .c, gcc it as a C program, but is deemed g ++ c ++ process; .cpp the suffix, both will be considered to be c ++ program, note that although c c ++ is a superset, but both the requirements of the syntax is different.
  automake is a tool for automatically generating Makefile.in from Makefile.am files. To generate Makefile.in, automake need to use perl, due for release created entirely under the GNU automake standard, there is no need perl in creation. libtool is a convenient tool to generate various libraries.
  pcre pcre-devel: Nginx compiled in need PCRE (Perl Compatible Regular Expression), because the Nginx Rewrite module and a core module uses HTTP to PCRE regular expression syntax.
  zlip zlib-devel: nginx when compression is enabled, the need to support this module.
  openssl openssl-devel: open SSL when needed to support this module.

Download Nginx

cd /usr/src

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

tar xf nginx-1.4.2.tar.gz

cd /usr/src/nginx-1.4.2

./configure && make && make install

Upload file rz
upload files on Windows, hey
linux is not installed? ? ?

yum install lrzsz -y

Execution:
rz -y

Nginx compiled after the completion of the installation,

# 查看端口
netstat -ntlp | grep 80

# 查看 Nginx 配置文件
/usr/local/nginx/conf/nginx.conf

# 检查 Nginx 配置文件语法
/usr/local/nginx/sbin/nginx -t

[root@ nginx]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

# 启动 Nginx
/usr/local/nginx/sbin/nginx

# 平滑重启 Nginx
/usr/local/nginx/sbin/nginx -s reload

# 配置 Nginx 虚拟主机
即修改 其配置文件 nginx.conf
server{

    listen 80;
    server_name www.a.com;
    
    #access_log logs/host.access.log main;

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


server{  …… }
server{  …… }

等等 多个虚拟主机

# 配置完成 来个平滑重启,嘿嘿

修改Windows host 配置文件,使其解析到 自己瞎编的域名上。

路径:system32\drivers\etc\hosts
添加:  192.168.1.116 www.a.com
    192.168.1.116 www.b.com

# 查看 编译参数 
/usr/local/nginx/sbin/nginx -v

Nginx upgrade procedure

# 查看 编译参数

# 下载升级所需的 Nginx
tar xf nginx-1.6.1.tar.gz
cd nginx-1.6.1

/usr/local/nginx/sbin/nginx -V  ###查看编译参数

./configure --prefix=  #老版本的 编译参数

make    # *****不能执行 make install

# 备份旧 Nginx 执行文件
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

# 备份 二进制 文件
cp objs/nginx /usr/local/nginx/sbin/nginx   # 对新版本的objs

# 平滑重启 Nginx
/usr/local/nginx/sbin/nginx -s reload

Other relevant

9、重读配置文件和关闭服务:

[root@Server1 local]# /usr/local/nginx/sbin/nginx  #启动 服务
[root@Server1 local]# /usr/local/nginx/sbin/nginx   -s  reload  #不停止服务重读配置文件
[root@Server1 local]# /usr/local/nginx/sbin/nginx/nginx -s stop #停止服务  #停止服务
10.验证端口是否开启:

[root@Server1 sbin]# ps -ef | grep nginx
root     13228     1  0 Apr23 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx/nginx  #nginx的主进程,只有一个主进程
nginx    13229 13228  0 Apr23 ?        00:00:00 nginx: worker  process #nginx工作进程,默认只有一个,可以通过修改nginx.conf中的worker_processes  1; 参数启动多个工作进程
root     13295  1400  0 00:01 pts/0    00:00:00 grep --color=auto nginx

[root@Server1 local]# lsof -i:8090  #显示占用8090的进程
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 13337 root 6u IPv4 5932680 0t0 TCP *:8090 (LISTEN)
nginx 13338 nginx 6u IPv4 5932680 0t0 TCP *:8090 (LISTEN)

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

Installation compile php-fpm

./configure --prefix=/usr/local/php5 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2   
# make && make install

pm.max_children = 50   
pm.start_servers = 5   
pm.min_spare_servers = 2   
pm.max_spare_servers = 8   
pid = /lnmp/php5/var/run/php-fpm.pid

<h1>hello,everybody, i am nginx</h1>   
<?php   
        $link = mysql_connect('192.168.204.132','test141','123123');   
        if ($link)   
                echo "Success...";   
        else  
                echo "Failure...";   
    
        mysql_close();   
        phpinfo();   
?>

nginx startup script

#! /bin/bash
# chkconfig: 35 85 15  
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME
test -x $DAEMON || exit 0
d_start(){
    $DAEMON || echo -n " already running"
}
d_stop() {
    $DAEMON -s quit || echo -n " not running"
}
d_reload() {
    $DAEMON -s reload || echo -n " counld not reload"
}
case "$1" in
start)
    echo -n "Starting $DESC:$NAME"
    d_start
    echo "."
;;
stop)
    echo -n "Stopping $DESC:$NAME"
    d_stop
    echo "."
;;
reload)
    echo -n "Reloading $DESC configuration..."
    d_reload
    echo "reloaded."
;;
restart)
    echo -n "Restarting $DESC: $NAME"
    d_stop
    sleep 2
    d_start
    echo "."
;;
*)
    echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
    exit 3
;;
esac
exit 0

## 将shell脚本放入到 /etc/rc.d/init.d/中,并执行下列命令
## chmod +x /etc/rc.d/init.d/nginx (设置可执行权限)
## chkconfig --add nginx (添加系统服务)

Guess you like

Origin www.cnblogs.com/yes5144/p/11538327.html
Recommended