您的位置:首页 > 运维架构 > Nginx

生产环境中安装nginx实战

2018-08-26 23:29 302 查看
前言: nginx是俄罗斯人开发的开源的www服务软件。nginx现在在企业生产环境中用的非常多,尤其是牵涉到高并发的互联网产品,因此作为一个运维人员掌握nginx是必备技能。从大的方面来说具有三方面的功能(A.www的web服务80端口,B.负载均衡(反向代理proxy),C.web缓存) 。本文主要介绍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/



总结排错思想:
1>ping 192.168.0.104物理通不通
2>telnet 192.168.0.104 80浏览器到web服务通不通
3>服务器本地curl 192.168.0.104web服务开没开
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx 实战
相关文章推荐