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被广 ...
随机推荐
- python-希尔排序
希尔排序 希尔排序的实质就是分组插入排序,该方法又称缩小增量排序,因DL.Shell于1959年提出而得名. 希尔排序,也称递减增量排序算法,是插入排序的一种更高效的改进版本.希尔排序是非稳定排序算法 ...
- Go的基本环境配置
参考 https://golang.org/doc/install?download=go1.7.1.linux-amd64.tar.gz https://github.com/qlshine/the ...
- sql必知必会-总结篇
总结: 1.全书总览:数据查询.新增.删除:表的新增.更新操作:视图.存储过程.事务.索引的描述,高级sql功能:约束.触发器.索引 2.特色:术语简明定义,讲述最简单化.简而全面. 3.长进的地方: ...
- javascript基础知识2#数据类型
数据类型 typeof 操作符 undefined类型 boolean类型 Nubmer类型 NaN(not a number) 数值转换parseInt,parseFloat String类型 字符 ...
- metasploit快速入门
今天没上班,在小黑屋里看了一个一百多页的书<metasploit新手指南>,在此将笔记分享给大家.欢迎大家批评指正,共同学习进步. metasploit新手指南 笔记 kali 0 ...
- pudian
https://zh.wikipedia.org/wiki/%E7%89%B9%E5%BE%81%E7%A0%81 http://www.voidcn.com/blog/lionzl/article/ ...
- 虚拟机安装linux系统不能上网解决方法
周末闲来无事,用虚拟机安装了centos6.5系统,安装成功后发现不能连接网络,然后我就一脸蒙蔽了,无奈之下,只能百度查找问题,幸运的是,我还真找到了解决的方法,根据教程一步步操作,成功了!为了避免以 ...
- [算法题] Search in Rotated Sorted Array ii
题目内容 题目来源:LeetCode Suppose an array sorted in ascending order is rotated at some pivot unknown to yo ...
- Cognos配置管理
--Cognos配置管理 --------------------------2014/03/19 进入配置管理界面: /washome/cognos/c10/bin64 ./cogconfig.sh ...
- DB2 HADR备库归档问题
--DB2 HADR备库归档问题 --------------------------------2013/10/29 我们注意到在Oracle DataGuard中,备机中依然会设置LOG_ARCH ...