1、创建nignx用户

/usr/sbin/groupadd -f nginx
/usr/sbin/useradd -g nginx nginx

2、安装依赖

yum install gcc  gcc-c++ -y #默认有的话无须安装
yum install -y pcre-devel openssl-devel #依赖(支持Nginx服务访问,以https方式访问)

3、下载软件包&编译安装

wget -q http://nginx.org/download/nginx-1.14.2.tar.gz #下载软件包
tar xf nginx-1.14..tar.gz
cd nginx-1.14.
./configure --prefix=/usr/local/nginx-1.14. --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module #根据你的需求添加编译时要带的模块
make && make install

4、软链接启动

ln -s /usr/local/nginx-1.14. /usr/local/nginx
# 这条ln命令的意义十分深远重大。这是生产环境的经验。
# 将Nginx安装路径通过软链接方式更改为/usr/local/nginx/,方便人员使用。
# 安装时指定版本号路径是为了便于查看分区当前使用的版本,也方便以后升级。
/usr/local/nginx/sbin/nginx #启动nginx 若报错说明没有创建nginx用户或者是
ln -s /usr/local/nginx-1.14./sbin/nginx /usr/local/sbin/ #做条软连接直接用nginx启动
在nginx.conf中 把user nobody的注释去掉既可
netstat -lntup|grep 查看是否有80端口

5、查看nginx的编译参数

#/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.14.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.14.2 --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module

6、检查语法&平滑重启

nginx -t   #检查语法是否正常
nginx -s reload #平滑重启

7、精简nginx配置文件

egrep -v "#|^$" nginx.conf.default >nginx.conf  #精简化/最小化默认nginx.conf配置文件信息

8、配置nginx负载均衡

# vim conf/nginx.conf
worker_processes ;
events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ;
upstream wang.com{ #服务器集群的名字
server 10.10.16.223: weight=;
server 10.10.16.252: weight=; }
server {
listen ;
server_name localhost;
location / {
proxy_pass http://wang.com; #以上面对应
proxy_redirect default;
}
error_page /50x.html;
location = /50x.html {
root html;
}
}
}

  标准的配置请写在vhost下面:

[root@linux-node1 conf]# cat nginx.conf
#user www;
worker_processes auto;
worker_rlimit_nofile ; events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ; log_format main '$remote_addr - $host [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time $upstream_addr $upstream_status $upstream_response_time $bytes_sent'; gzip on ;
gzip_min_length 1k;
gzip_buffers 16k;
gzip_comp_level ;
gzip_types text/plain application/x-javascript text/css application/xml application/json application/javascript text/javascript image/jpeg image/gif image/png;
gzip_disable "MSIE [1-6].";
gzip_vary on;
#其他的在着重添加优化参数 include vhost/*.conf; }

  处理逻辑的放在vhost下面:

[root@shenzhen conf]# pwd
/usr/local/nginx/conf
[root@shenzhen conf]# cat vhost/gunicorn.conf
server {
listen ;
server_name xx.xxx.xxx.xxx; #location / {
# root html;
# index index.html index.htm;
# } location / {
proxy_pass http://127.0.0.1:5001;
proxy_redirect default;
} error_page /50x.html;
location = /50x.html {
root html;
} access_log /data/logs/nginx/gunicorn_access.log main;
error_log /data/logs/nginx/gunicorn_error.log; }

9、终结版

  一键安装openresty,配置优化等

[root@linux-node1 ~]# cd /usr/local/src
[root@linux-node1 src]# git clone https://github.com/unixwang/linux-package.git
[root@linux-node1 src]# cd linux-package/
[root@linux-node1 linux-package]# yum localinstall -y jemalloc-4.5.-.x86_64.rpm openresty-1.15.8.1-.x86_64.rpm
[root@linux-node1 vhost]# cd /usr/local/openresty/nginx/conf/vhos
[root@linux-node1 vhost]# /usr/local/openresty/nginx/sbin/nginx

快速安装nginx的更多相关文章

  1. CentOS 6.4 快速安装Nginx笔记

    CentOS 6.4 快速安装Nginx笔记 本系列文章由ex_net(张建波)编写,转载请注明出处. http://blog.csdn.net/ex_net/article/details/9860 ...

  2. 在Mac OS X 下快速安装Nginx

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Helvetica; color: #8e68ff } p.p2 { margin: 0.0p ...

  3. CentOS用yum快速安装nginx

    增加nginx源 vim  /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/ ...

  4. centos7下快速安装Nginx服务器

    1.添加源 默认情况Centos7中无Nginx的源,最近发现Nginx官网提供了Centos的源地址.因此可以如下执行命令添加源: sudo rpm -Uvh http://nginx.org/pa ...

  5. Centos下快速安装Nginx

    1.准备工作 选首先安装这几个软件:GCC,PCRE(Perl Compatible Regular Expression),zlib,OpenSSL. Nginx是C写的,需要用GCC编译:Ngin ...

  6. 快速安装Nginx及配置详解(未完待续)

    导读: Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,从2007年被德国人开发出来后可以说在市场的占有率一路飙升,因为它支持高并 ...

  7. CentOS快速安装Nginx的方法,nginx如何启动重启停止

    1.防止 make: command not found,提前安装一些插件,取决于当前环境是否已安装,如果已经安装就不需要执行此命令 yum -y install gcc automake autoc ...

  8. Nginx的快速安装

    1. 准备工作 1. CenterOS7.x.vmware虚拟机,安装过程参考 https://jingyan.baidu.com/article/eae0782787b4c01fec548535.h ...

  9. zabbix快速安装(Ubuntu18.04, Nginx)

    ubuntu18.04快速安装zabbix4.0 https://blog.csdn.net/qq_33317586/article/details/83867756 需要安装的东西:nginx,ph ...

随机推荐

  1. 【洛谷P1483】序列变换

    题目大意:给定一个长度为 N 的序列,有 M 个操作,支持将下标为 x 的倍数的数都加上 y,查询下标为 i 的元素的值. 题解:由于查询操作很少,相对的,修改操作很多.若直接模拟修改操作,即:枚举倍 ...

  2. python3+django2 开发易语言网络验证(下)

    第六步:网络验证服务器端项目上线部署 功夫不负有心人,终于部署成功啦! 前期准备: 项目名:netauth 系统:百度云服务器下的Ubuntu16.4 软件:xshell(无论如何想办法用这个跟服务器 ...

  3. UI自动化学习路线

    1.web自动化 1.前端技术介绍 参考网址:http://www.w3school.com.cn/xml/xml_xsl.asp html /html5 js/jquery xml/xpath 参考 ...

  4. java方法笔记: split,instanceof,StringBuilder(),append(),string ,Integer,Math,正则表达式

    http://swiftlet.net/archives/709 如果分隔符在前方,会显示“”,在尾部不显示: *|做分割,需要加\\ API文档如下 1.instanceof 查看前者是否是后者的实 ...

  5. (最长回文子串 线性DP) 51nod 1088 最长回文子串

    输入一个字符串Str,输出Str里最长回文子串的长度. 回文串:指aba.abba.cccbccc.aaaa这种左右对称的字符串. 串的子串:一个串的子串指此(字符)串中连续的一部分字符构成的子(字符 ...

  6. Mysql+Keepalived双主热备高可用操作记录

    我们通常说的双机热备是指两台机器都在运行,但并不是两台机器都同时在提供服务.当提供服务的一台出现故障的时候,另外一台会马上自动接管并且提供服务,而且切换的时间非常短.MySQL双主复制,即互为Mast ...

  7. 【优秀的Sketch插件】PaintCode for Sketch for Mac 1.1

    [简介] PaintCode for Sketch 是一款结合了PaintCode和Sketch两款软件强大功能的插件,今天和大家分享最新的1.1版本,支持Sketch 40+版本,这个插件能够让你的 ...

  8. bzoj4326 树链剖分 + 线段树 // 二分 lca + 树上差分

    https://www.lydsy.com/JudgeOnline/problem.php?id=4326 题意:N个点的树上给M条树链,问去掉一条边的权值之后所有树链长度和的最大值最小是多少. 首先 ...

  9. Spring 在 xml配置文件 或 annotation 注解中 运用Spring EL表达式

    Spring  EL 一:在Spring xml 配置文件中运用   Spring EL Spring EL 采用 #{Sp Expression  Language} 即 #{spring表达式} ...

  10. SpringBoot笔记十一:html通过Ajax获取后端数据

    我们知道在Java Web中,前端的JSP可以使用EL表达式来获取Servlet传过来的数据Spring Boot中也有Thymeleaf模板可以使用th: text="${XXX}&quo ...