nginx 安装和配置
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 安装和配置的更多相关文章
- 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定
阿里云服务器Linux CentOS安装配置(八)nginx安装.配置.域名绑定 1.安装nginx yum -y install nginx 2.启动nginx service nginx star ...
- ubuntu server nginx 安装与配置
ubuntu server nginx 安装与配置 一:关于nginx http://wiki.ubuntu.org.cn/Nginx http://nginx.org/cn http://wiki. ...
- Nginx安装及配置详解【转】
nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...
- [转帖]Nginx安装及配置详解 From https://www.cnblogs.com/zhouxinfei/p/7862285.html
Nginx安装及配置详解 nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP ...
- Linux中Nginx安装与配置详解
转载自:http://www.linuxidc.com/Linux/2016-08/134110.htm Linux中Nginx安装与配置详解(CentOS-6.5:nginx-1.5.0). 1 N ...
- centos7系统下nginx安装并配置开机自启动操作
准备工作 我的centos7系统是最小化安装的, 缺很多库, 首先安装必须的运行库 ? 1 2 3 4 5 6 7 8 9 10 11 yum install wget gcc gcc-c++ pcr ...
- linux nginx安装以及配置
一.Nginx简介 Nginx (“engine x”) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗斯访问量第二的R ...
- Nginx安装以及配置
安装编译工具及库文件 1 yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 安装 PCRE 下载 PC ...
- Nginx安装与配置-Centos7
Nginx是一款高性能免费开源网页服务器,也可用于反向代理和负载均衡服务器.该软件由伊戈尔·赛索耶夫于2004年发布,2019年3月11日,Nginx被F5 Networks以6.7亿美元收购.201 ...
- LVS+Nginx(LVS + Keepalived + Nginx安装及配置)
(也可以每个nginx都挂在上所有的应用服务器) nginx大家都在用,估计也很熟悉了,在做负载均衡时很好用,安装简单.配置简单.相关材料也特别多. lvs是国内的章文嵩博士的大作,比nginx被广 ...
随机推荐
- decode
含义解释: decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 该函数的含义如下:IF 条件=值1 THEN RETURN(翻译值1)ELSIF 条件=值2 THEN ...
- 关于appcompat_v7兼容包的详细说明
1.appcompat_v7包的由来? appcompat_v7是Google提供的向下兼容包,是针对API level 7(Android2.1)及以上版本所开发的,其作用是为了让兼容低版本API( ...
- mysql索引 索引优缺点
mysql索引索引优化 1.什么是索引?索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息. 2.作用是什么?索引的作用相当于图书的目录,可以根据目录中的页码快 ...
- .NET Core资源汇总
前言 首先庆祝.NET Core 2.0今天发布. 最近一两年.NET的关注度直线下降, 大部分开发人员转去了其他平台, 国内的机会也越来越少了. 行情虽然如此, 仍在坚守.NET平台的开发人员还是要 ...
- 【性能测试工具】- Http_Load
优点:参数少:缺点:url.txt文件要求较高,不如siege方便 http_load是ACME实验室开发的,这个工具以并发方式运行,用以测试web服务器的吞吐量与负载.它不同于其它压力测试工具的是, ...
- Kettle安装和配置
0x01 Kettle软件概览 Spoon:集成开发环境 Kitchen:作业的命令行运行程序,可以通过Schell脚本来调用 Pan:转换的命令行程序 Carte:轻量级的HTTP服务,后台运行,监 ...
- DATAGUARD常用管理命令
--DATAGUARD常用管理命令 ----------------------------2014/04/22 备用服务器的管理模式与只读模式 1.1备库启动到管理恢复模式 SQL>shutd ...
- python中类的属性(class attribute)的解释
python中的类叫 class object,类的实例叫instance object. 类 Class Objects 类拥有两种操作,1.类属性 attribute references 2.实 ...
- nmake学习笔记
1.命令行中调用nmake的基本语法: namke /f makefile /x stderrfile [macrodefs] [targets] 其中makefile为makefile文件,/x ...
- css基础知识之属性选择器
css属性选择器及属性和值选择器如下: <!DOCTYPE html> <html lang="en"> <head> <meta cha ...