生产环境中安装nginx实战

前言: nginx现在在企业生产环境中用的非常多,尤其是牵涉到高并发的互联网产品,因此作为一个运维人员掌握nginx是必备技能。本文主要介绍nginx的安装。


零>环境准备

centos7;nginx-1.6.2;


一>准备

1>安装pcre 兼容中文正则表达式 ,

[root@lll usr]# yum install pcre pcre-devel -y

2>安装openssl,

[root@lll usr]# yum install openssl openssl-devel -y

3>创建支持nginx运行的用户(linux中的文件和进程都需要用户来支持的,-M参数不建家目录):

[root@lll usr]# useradd nginx -s /sbin/nologin -M


二>安装nginx

[root@lll nginx-1.6.2]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.2  --with-http_stub_status_module --with-http_ssl_module

[root@lll nginx-1.6.2]# echo $?  ---返回0代表安装正常。

0

[root@lll nginx-1.6.2]# make      ---根据Makefile编译源代码,连接,生成目标文件,可执行文件。

[root@lll nginx-1.6.2]# make  install ---将编译成功的可执行文件安装到系统目录中,一般为/usr/local/bin目录。

[root@lll nginx-1.6.2]# cd ..

[root@lll usr]# ln -s /application/nginx-1.6.2/ /application/nginx  ---制作软链接(快捷方式)去掉nginx的版本号


三>启动nginx

[root@lll usr]# /application/nginx/sbin/nginx -t    ----检测语法

nginx: the configuration file /application/nginx-1.6.2/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.2/conf/nginx.conf test is successful

[root@lll usr]# /application/nginx/sbin/nginx      -----启动nginx

[root@lll usr]# netstat -lntup|grep nginx           ----搜索nginx进程是否启动

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7152/nginx: master

[root@lll usr]# lsof -i:80                                        ----根据端口反查nginx进程是否启动

COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

nginx   7152  root    6u  IPv4  41603      0t0  TCP *:http (LISTEN)

nginx   7153 nginx    6u  IPv4  41603      0t0  TCP *:http (LISTEN)

[root@lll usr]# curl 192.168.0.104                         -----也可以curl来检查

<!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://nginx.org/">nginx.org</a>.<br/>

Commercial support is available at

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


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

</body>

</html>


四>windows浏览器访问(192.168.0.104为安装nginx的服务器的ip地址)

http://192.168.0.104/

RG$I~{(3$M$2MAA3CK5J{N8.png


总结排错思想:

1>ping 192.168.0.104物理通不通

2>telnet 192.168.0.104 80浏览器到web服务通不通

3>服务器本地curl 192.168.0.104web服务开没开


猜你喜欢

转载自blog.51cto.com/11218855/2164642