nginx服务搭建

一、nginx简介:

  国内常用的的是nginx,nginx是一个开源的,支持高性能、高并发的www服务和代理服务软件,nginx因具有高并发(特别是静态资源,)占用系统资源少等特性,且功能丰富而逐渐流行起来,从软件大的功能应用方面,nginx不但是一个优秀的web服务软件,还可以具有反向代理负载均衡功能和缓存服务功能,在方向代理负载均衡方面,他类似于大名鼎鼎的LVS负载均衡及haproxy专业代理软件,但是nginx部署起来更为简单,方便,在缓存服务功能方面,它有类似于squid等专业的缓存服务软件,当前流行的nginx web组合被称为LNMP或LEMP(LNMP 即 linux nginx mysql php)其中 LEMP (E取自Nginx (engine x))

二、nignx的搭建

//下载rewrite支持及一些源
[root@localhost data]# yum install pcre pcre-devel -y
[root@localhost data]# yum -y install gcc
[root@localhost data]# yum install openssl openssl-devel -y
//下载nginx
http://nginx.org/en/download.html      -->  download   -->   nginx-1.6.3
//将下载好的tar包放到自己规划的路径下并解压
[root@localhost pandj]# ll /home/pandj/
total 788
-rw-r--r--. 1 root root 805253 Jul 31  2018 nginx-1.6.3.tar.gz
[root@localhost pandj]# ll
total 788
drwxr-xr-x. 8 pandj pandj    158 Apr  7  2015 nginx-1.6.3
-rw-r--r--. 1 root  root  805253 Jul 31  2018 nginx-1.6.3.tar.gz
//配置并编辑nginx
[root@localhost pandj]# cd nginx-1.6.3
[root@localhost nginx-1.6.3]# ./configure --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --prefix=/application/nginx-1.6.3/
[root@localhost nginx-1.6.3]# echo $?
0
[root@localhost nginx-1.6.3]# make
[root@localhost nginx-1.6.3]# make install
//创建用户
[root@localhost nginx-1.6.3] useradd www
//创建一个软连接,方便后续管理
[root@localhost application]# ln -s /application/nginx-1.6.3/ /application/nginx
//至此nginx已经安装成功,检查语法并重启。
[root@localhost application]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful
[root@localhost sbin]# cd /application/nginx/sbin/nginx 
//浏览器访问服务器地址,可以看到welcome nginx

  

  一些参考文档:搭建nginx + mysql + php 的环境配置及原理 :https://www.jianshu.com/p/495a02eb2672

  如果是在阿里云上部署的nginx,在配置文件中修改了端口还是不能访问是因为需要在阿里云上修改策略,默认只开放22和3306端口,在阿里云——云服务器——安全组规则——配置规则——添加安全组规则——添加所需要访问的端口。

  上诉参考案例:https://blog.csdn.net/liyuxing6639801/article/details/72588074

原文地址:https://www.cnblogs.com/pandj/p/9396898.html