1. 安装相关依赖

yum install readline-devel pcre-devel openssl-devel zlib-devel gcc gcc-c++  gd-devel libxml2-devel

2. 添加nginx第三方模块

1) pcre(rewrite正则表达式的支持):ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
2) libressl(加密解密):http://ftp.openbsd.org/pub/OpenBSD/LibreSSL/
3) openssl(加密解密):ftp://ftp.openssl.org/source
4) zlib(数据压缩):http://zlib.net/ http://zlib.net/zlib-1.2.8.tar.gz
5) ngx_cache_purge(缓存清除扩展模块):https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
6) nginx_upstream_check_module(负载均衡):https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
7) echo-nginx-module(模块,方便输出用的):https://github.com/openresty/echo-nginx-module/archive/v0.60.tar.gz
8)nginx:http://nginx.org/download/nginx-1.10.1.tar.gz

3. nginx编译安装

nginx 1.10.2 install on CentOS 6.x:
./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module \
--with-ipv6 \
--with-pcre=../pcre-8.40 \
--with-pcre-jit \
--with-openssl=../libressl-2.5.1 \
--with-zlib=../zlib-1.2.11/ \
--add-module=../ngx_cache_purge-2.3/ \
--add-module=../nginx_upstream_check_module-0.3.0/ \
--add-module=../echo-nginx-module-0.60/ \
--with-ld-opt=-lrt make
make install

4.yum 安装nginx

yum install nginx

5.修改防火墙

/etc/sysconfig/iptables
/etc/init.d/iptables stop
/etc/init.d/iptables start
#80端口可以访问
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

6.nginx 配置文件结构

默认的配置文件:

#user  nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

7.nginx 文件结构

events {         #events块
...
} http #http块
{
... #http全局块
server #server块
{
... #server全局块
location #location块
{
...
}
location
{
...
}
}
server
{
...
}
... #http全局块
}
user www www;  #用户组
worker_processes 2; #nginx要开启的进程数
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000; #使用该选项可以绑定worker进程和CPU
pid /var/run/nginx.pid; #nginx进程运行文件存放地址
events {
accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on
multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off
use epoll; #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
worker_connections 1024; #最大连接数,默认为512
}
http {
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型,默认为text/plain #access_log off; #取消服务日志
log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for'; #自定义格式
access_log log/access.log myFormat; #combined为日志格式的默认值 sendfile on; #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。
sendfile_max_chunk 100k; #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。 keepalive_timeout 65; #连接超时时间,默认为75s,可以在http,server,location块。
error_page 404 https://www.baidu.com; #错误页 #负载均衡
upstream mysvr {
server 127.0.0.1:7878;
server 192.168.10.121:3333 backup;
} server {
listen 80; #监听端口
root path; #根目录
index index.html; #设置默认页
server_name a.com; #监听地址 location / { #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
proxy_pass http://mysvr; #请求转向mysvr 定义的服务器列表
deny 127.0.0.1; #拒绝的ip
allow 172.18.5.54; #允许的ip
}
}
}

nginx 安装和配置的更多相关文章

  1. 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定

    阿里云服务器Linux CentOS安装配置(八)nginx安装.配置.域名绑定 1.安装nginx yum -y install nginx 2.启动nginx service nginx star ...

  2. ubuntu server nginx 安装与配置

    ubuntu server nginx 安装与配置 一:关于nginx http://wiki.ubuntu.org.cn/Nginx http://nginx.org/cn http://wiki. ...

  3. Nginx安装及配置详解【转】

    nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...

  4. [转帖]Nginx安装及配置详解 From https://www.cnblogs.com/zhouxinfei/p/7862285.html

    Nginx安装及配置详解   nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP ...

  5. Linux中Nginx安装与配置详解

    转载自:http://www.linuxidc.com/Linux/2016-08/134110.htm Linux中Nginx安装与配置详解(CentOS-6.5:nginx-1.5.0). 1 N ...

  6. centos7系统下nginx安装并配置开机自启动操作

    准备工作 我的centos7系统是最小化安装的, 缺很多库, 首先安装必须的运行库 ? 1 2 3 4 5 6 7 8 9 10 11 yum install wget gcc gcc-c++ pcr ...

  7. linux nginx安装以及配置

    一.Nginx简介 Nginx (“engine x”) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗斯访问量第二的R ...

  8. Nginx安装以及配置

    安装编译工具及库文件 1 yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 安装 PCRE 下载 PC ...

  9. Nginx安装与配置-Centos7

    Nginx是一款高性能免费开源网页服务器,也可用于反向代理和负载均衡服务器.该软件由伊戈尔·赛索耶夫于2004年发布,2019年3月11日,Nginx被F5 Networks以6.7亿美元收购.201 ...

  10. LVS+Nginx(LVS + Keepalived + Nginx安装及配置)

    (也可以每个nginx都挂在上所有的应用服务器)  nginx大家都在用,估计也很熟悉了,在做负载均衡时很好用,安装简单.配置简单.相关材料也特别多. lvs是国内的章文嵩博士的大作,比nginx被广 ...

随机推荐

  1. 使用gitLab 或 github 关联本地仓库

    要先在git里面注册自己的邮箱 然后: git commit -m 是为本次提交命名 刷新gitLab 发现更新了

  2. httpd页面用户访问认证控制

    [root@liubin-pc ~]# yum install -y httpd 客户机地址限制 通过配置Order.Deny from.Allow from 来限制客户机 allow.deny :先 ...

  3. NYOJ--42--dfs--一笔画问题

    /* Name: NYOJ--42--一笔画问题 Author: shen_渊 Date: 18/04/17 15:22 Description: 这个题用并查集做,更好.在练搜索,试试手 本来用的v ...

  4. mysql 查询性能优化第一章 为什么查询速度会慢

    一 为什么查询速度会慢 在尝试编写快速的查询之前,咱们需要清除一点,真正重要的是响应时间.如果把查询看成是一个任务,那么它由一系列子任务组成,每个子任务都会消耗一定的时间.如果要有 优化查询,实际上要 ...

  5. 社群系统 ThinkSNS+ 中如何利用 Laravel 表单验证来验证用户名的?(我朝独有需求,两个字母占一个汉字。。。)

    ThinkSNS+后端框架使用laravel,每周和 laravel master 保持同步,而后台和 html 5 则采用 vue 开发.语言特性方面,采用 php 7 的严格模式. 言归正传,之所 ...

  6. [INS-30060]:Check for group existence failed

    --[INS-30060]:Check for group existence failed -------------------------------------------------2013 ...

  7. C# 调用 C++ DLL方法

    在C# 中,可以通过 DllImport 调用C++ 的非托管DLL程序. VS2010中C#调用C++的DLL示例: 一.新建C++ DLL程序 1.新建 C++ Win32项目,类型为DLL. 生 ...

  8. Mac实用操作技巧(三)

    远程协助 很多场景下需要用到远程协助,比如你遇到了某个搞不定的bug需要他人帮助,但是别人却不在身边,这时就需要别人通过网络来远程协助你解决问题.在Windows下有不少优秀软件,比如TeamView ...

  9. ASP.NET Core Razor页面 vs MVC

    作为.NET Core 2.0发行版的一部分,还有一些ASP.NET的更新.其中之一是添加了一个新的Web框架来创建"页面",而不需要复杂的ASP.NET MVC.新的Razor页 ...

  10. Python二分法查找及变种分析

    基于Python3 普通二分法查找目标值的index 二分法查找的思路很简单,先确定好列表nums的一头start一尾end,中间值middle根据头尾数值之和用地板除法除以2,即(start + e ...