首页 > 代码库 > 安装Nginx

安装Nginx

  Linux下安装Nginx,需要保证一些依赖的库先被安装好。

1、安装好g++、ssl、pcre、zlib库文件

2、安装Nginx

  1)执行./configure 命令编译,需指定一些编译参数

  --prefix=  定义安装目录(默认/usr/local/nginx)

  --sbin-path=  定义nginx可以执行文件路径(默认prefix/sbin/nginx)

  --conf-path=  定义nginx配置文件目录(默认prefix/conf/nginx.conf)

  --pid-path=  定义nginx.pid文件路径(默认prefix/logs/nginx.pid)

  --with-pcre=  定义pcre库文件路径(rewrite需要用到)

  --with-zlib=  定义zlib库文件路径(gzip压缩用到)

./configure --with-http_ssl_module             --with-pcre=/usr/local/pcre-8.36              --with-zlib=/usr/local/zlib-1.2.8

  不指定的参数就使用默认值。

  2)安装命令 make & make install

 

3、执行启动命令

/usr/local/nginx/sbin/nginx

 

4、看看进程id和端口

[root@Luxh-01 logs]# lsaccess.log  error.log  nginx.pid[root@Luxh-01 logs]# cat nginx.pid 16275[root@Luxh-01 logs]# lsaccess.log  error.log  nginx.pid[root@Luxh-01 logs]# cat nginx.pid16275[root@Luxh-01 logs]# ps -ef|grep nginxroot     16275     1  0 19:17 ?        00:00:00 nginx: master process ./nginxnobody   16276 16275  0 19:17 ?        00:00:00 nginx: worker processroot     19463  5258  0 21:08 pts/0    00:00:00 grep nginx[root@Luxh-01 logs]# 
[root@Luxh-01 logs]# netstat -ano|grep 80tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      off (0.00/0/0)udp        0      0 :::58067                    :::*                                    off (0.00/0/0)unix  2      [ ]         DGRAM                    18807  unix  2      [ ]         DGRAM                    12803  [root@Luxh-01 logs]#

 

5、默认的日志文件目录

[root@Luxh-01 logs]# pwd/usr/local/nginx/logs[root@Luxh-01 logs]# lsaccess.log  error.log  nginx.pid

 

6、nginx编译选项可参考

http://nginx.org/en/docs/configure.html

 

安装Nginx