linux下编译安装Nginx

2017-04-28 11:49:23 8302

1、安装Nginx所需的pcre包和openssl-devel

yum install pcre pcre-devel -y

yum install openssl openssl-devel -y

 

或者

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz

tar zxf pcre-8.30.tar.gz

cd pcre-8.30

./configure

make

make install

 

安装完检查结果

rpm -qa pcre pcre-devel

rpm -qa openssl openssl-devel

 

2、开始安装Nginx

cd /home/chenct/tools

wget

useradd nginx -s /sbin/nologin -M

tar zxf nginx-1.2.9.tar.gz

cd nginx-1.2.9

./configure --user=nginx --group=nginx --prefix=/application/nginx-1.2.9 --with-http_stub_status_module --with-http_ssl_module

make && make install

ln -s /application/nginx-1.2.9 /application/nginx

ll /application/nginx

 

3、启动Nginx

启动前检查配置文件语法

/application/nginx/sbin/nginx -t

 

启动Nginx服务

/application/nginx/sbin/nginx

 

4、检查是否启动成功

查看Nginx对应服务端口是否启动成功

[root@chonter ~]# lsof -i :80

COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

nginx   1893  root    6u  IPv4  12136      0t0  TCP *:http (LISTEN)

nginx   1894 nginx    6u  IPv4  12136      0t0  TCP *:http (LISTEN)

You have new mail in /var/spool/mail/root

 

[root@chonter ~]# netstat -lnt|grep 80

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN

 

5、测试访问浏览器输入ip地址,出现“welcome to nginx!”表示安装成功。

 

6LINUX下可通过wget 192.168.10.109命令检测是否启动成功。

[root@chonter ~]# wget 192.168.10.109

--2017-04-27 13:58:57--  http://www.landui.com/

正在连接 192.168.10.109:80... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:612 [text/html]

正在保存至: index.html.2

100%[================================================================>] 612         --.-K/s   in 0s     

2017-04-27 13:58:57 (66.5 MB/s) - 已保存 index.html.2 [612/612])

 

7、或者用curl命令检测

[root@chonter ~]# curl 192.168.10.109

<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

<style>

    body {

        width: 35em;

        margin: 0 auto;

        font-family: Tahoma, Verdana, Arial, sans-serif;

    }

</style>

</head>

<body>

<h1>Welcome to nginx!</h1>

<p>If you see this page, the nginx web server is successfully installed and

working. Further configuration is required.</p>

<p>For online documentation and support please refer to

<a href="http://www.landui.com/">nginx.org</a>.<br/>

Commercial support is available at

<a href="http://www.landui.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>

</body>

</html>


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: