nginx1.11 linux,linux 安装nginx1.11.1

1.下载

rewrite 模块需要

pcre:

http://exim.mirror.fr/pcre/

http://exim.mirror.fr/pcre/pcre-8.38.tar.gz

ssl 功能需要 openssl:

https://www.openssl.org/source/

https://www.openssl.org/source/openssl-fips-2.0.12.tar.gz

gzip 模块需要 zlib:

http://www.zlib.net/

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

(有问题)

http://download.csdn.net/download/qin1174586290/6364757

nginx:

http://nginx.org/en/download.html

http://nginx.org/download/nginx-1.11.1.tar.gz

2.安装 zlib(使用root):

#tar xzfv zlib-1.2.8.tar.gz

#cd zlbi-1.2.8

#./configure

--prefix=/usr/local/zlib

#make && make install

3.安装openssl-fips-2.0.12.tar.gz(使用root)

# tar -zxvf

openssl-fips-2.0.12.tar.gz

# cd openssl-fips-2.0.12

# ./config

--prefix=/usr/local/openssl

# make & make install

4.安装pcre(使用root)

C/C++的编译环境(g++,gcc):# sudo apt-get install

build-essential

# tar -zxvf pcre-8.38.tar.gz

# cd pcre-8.38

#

./configure --prefix=/usr/local/pcre

# make && make install

5.安装nginx(使用root)

#tar -xzvf nginx-1.11.1.tar.gz

#cd nginx-1.11.1

# ./configure --prefix=/usr/local/nginx

--with-pcre=../pcre-8.38 --with-zlib=../zlib-1.2.8

--with-openssl=../openssl-fips-2.0.12

# make && make install

6.检测是否安装成功

# cd

/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

7.启动nginx

# ./nginx

查看端口:netstat -ntlp

浏览器:localhost

8.最近配置nginx的时候,发现有个模块在编译的时候没有考虑到。由于nginx模块都是编译到nginx执行文件中的,所以我们添加模块的话需要重新编译。

shell>cdnginx-1.11.1

shell>./configure--重新编译的参数

shell>make

make完成之后,不要makeinstall,直接把编译好的nginx文件替换原来的nginx文件即可。

shell>kill

-9 nginxpid

shell>cp/usr/local/nginx/sbin/nginx/usr/local/nginx/sbin/nginx.bak

shell>cpobjs/nginx/usr/local/nginx/sbin/nginx

shell>./nginx

9.添加监控http_stub_status_module模块

# ./configure --prefix=/usr/local/nginx

--with-http_stub_status_module--with-pcre=../pcre-8.38

--with-zlib=../zlib-1.2.8

--with-openssl=../openssl-fips-2.0.12​

#make

按步骤8复制nginx文件.​​

修改nginx.conf

在nginx.conf的server块中添加如下代码

location /nginx_status {

# Turn

on nginx stats

stub_status on;

# I do

not need logs for stats

access_log  off;

#

Security: Only allow access from 192.168.1.100 IP #

#allow

192.168.1.100;

# Send

rest of the world to /dev/null #

#deny

all;

}

建立软链接

ln -s

/usr/local/nginx/sbin/nginx /usr/bin/nginx

10.查看已安装的 Nginx 是否包含

stub_status 模块​

#./nginx -V​

nginx version: nginx/1.11.1

built by gcc 5.2.1 20151010 (Ubuntu

5.2.1-22ubuntu2)

configure arguments: --prefix=/usr/local/nginx

--with-http_stub_status_module --with-pcre=../pcre-8.38

--with-zlib=../zlib-1.2.8 --with-openssl=../openssl-fips-2.0.12

#curl

127.0.0.1/nginx_status​

Active connections: 4

server accepts handled

requests

30 30 262

Reading: 0 Writing: 2 Waiting: 2

active connections – 活跃的连接数量

​server accepts

handled requests — 总共处理了30个连接 , 成功创建30次握手, 总共处理了262个请求

​reading —

读取客户端的连接数.

​writing —

响应数据到客户端的数量

​waiting — 开启

keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx

已经处理完正在等候下一次请求指令的驻留连接.

11.命令:

重新启动:

#./ngnix -s reload

停止:

#./nginx -s stop

12.location 配置

http://www.cnblogs.com/lidabo/p/4169396.html​

13 安装服务

新建文件nginx,内容如下:

#!/bin/sh

#

# chkconfig:  2345 10 90

# nginx - this script starts and stops the nginx

daemon

#

# description: Nginx is an HTTP(S) server, HTTP(S) reverse

\

#  proxy and IMAP/POP3 proxy

server

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {

echo

$"Starting $prog: "

#daemon $nginx -c

$NGINX_CONF_FILE

${nginx}  -c

$NGINX_CONF_FILE

echo

$"Start $prog  :

ok"

}

stop() {

echo

$"Stopping $prog: "

killall -9

nginx

echo

$"Stop $prog  :ok "

}

restart() {

stop

sleep 5

start

}

reload() {

echo

$"Reloading $prog: "

${nginx} -c $NGINX_CONF_FILE  -s

reload

echo

$"Reloading $prog: ok"

}

force_reload() {

restart

}

configtest() {

${nginx} -t -c

$NGINX_CONF_FILE

}

rh_status() {

ps -ef | grep

nginx

}

rh_status_q() {

rh_status

>/dev/null 2>&1

}

case "$1" in

start)

start ;;

stop)

stop;;

restart)

$1 ;;

reload)

$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

​把nginx复制到/etc/init.d 下

设置权限

#cd /etc/init.d

#chmod 755 tomcat

启动:​

#service nginx start​ 或 #./nginx start

出现问题的话试着执行:

# systemctl start

nginx.service

# systemctl enable

nginx.service

#systemctl start  nginx​

#systemcltl status nginx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值