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. 微信小程序开发基础知识总结

    微信小程序在无论在功能.文档及相关支持方面,都是优于前面几种微信账号类型,它提供了很多原生程序才有的接口,使得我们的小程序在很多方面突破H5页面应用的限制,更加接近原生程序的功能,因此微信小程序具有很 ...

  2. CentOS 6 下无法wget https链接的解决方法

    CentOS6下最高版本的wget是1.11,但非常遗憾的是这个版本有bug,是没办法用来下载https链接的东西的,所以有些人为了避免这种情况会帮脚本加上不检查ssl的参数--no-check-ce ...

  3. 使用Node.js实现简易MVC框架

    在使用Node.js搭建静态资源服务器一文中我们完成了服务器对静态资源请求的处理,但并未涉及动态请求,目前还无法根据客户端发出的不同请求而返回个性化的内容.单靠静态资源岂能撑得起这些复杂的网站应用,本 ...

  4. swift 获取文件大小

    //获取文件大小 func getSize(url: URL)->UInt64 { var fileSize : UInt64 = 0 do { let attr = try FileManag ...

  5. 小兴趣:用python生成excel格式座位表

    脚本分两个文件: 1.生成二维随机列表:GenerateLocaltion.py 2.将列表导入excel文件:CreateExcel.py 先上GenerateLocaltion.py: impor ...

  6. 【水题】HDU--1280 前m大的数

    还记得Gardon给小希布置的那个作业么?(上次比赛的1005)其实小希已经找回了原来的那张数表,现在她想确认一下她的答案是否正确,但是整个的答案是很庞大的表,小希只想让你把答案中最大的M个数告诉她就 ...

  7. 67. Add Binary【LeetCode】

    67. Add Binary Given two binary strings, return their sum (also a binary string). For example,a = &q ...

  8. HTML5 — Wed SQL 本地数据库示例

    1 <!DOCTYPE html>2 <html lang="en">3 <head>4 <meta charset="UTF- ...

  9. FPS手游如何脱颖而出?看《CF手游》的性能突破之路

    WeTest导读 俗话说:用户体验不谈性能就是耍流氓. 在PC游戏上的性能问题并没有那么明显, 加个内存换个CPU或者刷个主频就能轻松搞定:到了手游时代后情况则显得比较严峻,捉襟见肘的内存使得资源加载 ...

  10. SQL SERVER镜像切换

    --SQL SERVER镜像切换 ------------------------------2013/11/30 切换条件   高性能 没有见证服务器的高安全性模式 具有见证服务器的高安全性模式 自 ...