Centos6 安装nginx
一、编译安装nginx
1、安装nginx所需要的库pcre,pcre的全称为:perl compatible regular expression即perl正则表达式,是为了使nginx具备URL重写功能的rewrite模块
[root@web01 ~]# yum install pcre pcre-devel -y ####安装[root@web01 ~]# rpm -qa pcre pcre-devel ####检查pcre-devel-7.8-7.el6.x86_64pcre-7.8-7.el6.x86_64
2、安装nginx
[root@web01 ~]# yum install openssl-devel openssl -y ###安装nginx基础依赖包[root@web01 ~]# rpm -qa openssl-devel openssl ###检查是否安装成功openssl-1.0.1e-57.el6.x86_64openssl-devel-1.0.1e-57.el6.x86_64[root@web01 ~]# mkdir -p /server/tools ######创建一个目录,管理下载的工具软件[root@web01 ~]# useradd nginx -s /sbin/nologin -M #####添加nginx用户,不需要登陆,不需要家目录[root@web01 ~]# cd /server/tools/[root@web01 tools]# tar xf nginx-1.6.3.tar.gz #####解压nginx,软件请自行下载 [root@web01 tools]# cd nginx-1.6.3[root@web01 nginx-1.6.3]# mkdir -p /application/nginx-1.6.3 创建nginx安装目录[root@web01 nginx-1.6.3]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module ###配置安装参数checking for OS + Linux 2.6.32-431.el6.x86_64 x86_64checking for C compiler ... not found ./configure: error: C compiler cc is not found #####没有安装编译环境 [root@web01 nginx-1.6.3]# yum install gcc gcc-c++ -y ######安装编译工具[root@web01 nginx-1.6.3]# rpm -qa gcc gcc-c++ ###检查gcc-c++-4.4.7-18.el6_9.2.x86_64gcc-4.4.7-18.el6_9.2.x86_64[root@web01 nginx-1.6.3]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module ##重新配置.......省略.......Configuration summary + using system PCRE library + using system OpenSSL library + md5: using OpenSSL library + sha1: using OpenSSL library + using system zlib library nginx path prefix: "/application/nginx-1.6.3/" ###安装目录 nginx binary file: "/application/nginx-1.6.3//sbin/nginx" #####执行程序 nginx configuration prefix: "/application/nginx-1.6.3//conf" ####配置文件目录 nginx configuration file: "/application/nginx-1.6.3//conf/nginx.conf" #####主配置文件 nginx pid file: "/application/nginx-1.6.3//logs/nginx.pid" ####pid文件 nginx error log file: "/application/nginx-1.6.3//logs/error.log" ####错误日志 nginx http access log file: "/application/nginx-1.6.3//logs/access.log" ####访问控制文件 nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"[root@web01 nginx-1.6.3]# make [root@web01 nginx-1.6.3]# make install ####安装[root@web01 nginx-1.6.3]# ln -s /application/nginx-1.6.3 /application/nginx ####软连接到/application/nginx,方便管理软件版本;##################注释################--prefix=/application/nginx-1.6.3 安装路径--user=nginx 指定进程用户权限--group=nginx 指定进程用户组权限--with-http_stub_status_module 激活nginx状态信息--with-http_ssl_module 激活ssl加密功能
3、启动并检查nginx
[root@web01 nginx-]# /application/nginx/sbin/nginx -t ########-t 检查配置文件 nginx: the configuration file /application/nginx-//conf/nginx.conf syntax is ok nginx: configuration file /application/nginx-//conf/nginx.conf test is successful [root@web01 nginx-]# /application/nginx/sbin/nginx ######启动nginx [root@web01 nginx-]# lsof -i :80 #####查看nginx端口是否成功启动 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx root 0t0 TCP *:http (LISTEN) nginx nginx 0t0 TCP *:http (LISTEN)
4、客户端验证
[root@web01 ~]# /etc/init.d/iptables stop ####关闭防火墙[root@web01 ~]# chkconfig iptables off ####关闭防火墙开机启动[root@web01 ~]# getenforce ###检查selinux状态,为关闭状态,如果不是请自行关闭Disabled[root@web01 ~]# ip addr
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN
link/loopback ::::: brd :::::
inet scope host lo
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :0c::7d::f3 brd ff:ff:ff:ff:ff:ff
inet brd 192.168.127.255 scope global eth0 #####服务器地址
inet6 fe80::20c:29ff:fe7d:93f3/ scope link
valid_lft forever preferred_lft foreverwindows客户端在浏览器输入http://192.168.127.11
也可在本地用命令检测
[root@web01 ~]# wget 127.0.0.1
--2018-06-05 17:22:27-- http://127.0.0.1/
正在连接 127.0.0.1:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:612 [text/html]
正在保存至: “index.html”
100%[=========================================================================>] 612 --.-K/s in 0s
2018-06-05 17:22:27 (50.2 MB/s) - 已保存 “index.html” [612/612])
二、nginx目录结构和可加载模块功能
1、目录结构
[root@web01 ~]# tree /application/nginx /application/nginx ├── client_body_temp ├── conf #####nginx配置文件目录 │ ├── fastcgi.conf ######fastcgi相关参数的配置文件 │ ├── fastcgi.conf.default ######fastcgi原始备份 │ ├── fastcgi_params ####fastcgi的参数文件 │ ├── fastcgi_params.default │ ├── koi-utf │ ├── koi-win │ ├── mime.types ####媒体类型 │ ├── mime.types.default │ ├── nginx.conf ####nginx默认配置文件 │ ├── nginx.conf.default │ ├── scgi_params ####scgi相关参数文件,一般用不到 │ ├── scgi_params.default │ ├── uwsgi_params #####uwsgi相关参数文件,一般用不到 │ ├── uwsgi_params.default │ └── win-utf ├── fastcgi_temp ####fastcgi临时数据目录 ├── html ####bginx的默认站点目录 │ ├── 50x.html ####错误页面 │ └── index.html ###默认首页文件 ├── logs │ ├── access.log ####nginx默认访问日志文件 │ ├── error.log ####默认错误日志文件 │ └── nginx.pid #####pid文件 ├── proxy_temp ####临时目录 ├── sbin ####命令目录 │ └── nginx ├── scgi_temp ####临时目录 └── uwsgi_temp ###临时目录
2、功能模块
- ngx_http_core_module:包括一些核心的http参数配置,对应nginx的配置为http区块部分
- ngx_http_access_module:访问控制模块,用来控制网站用户对nginx的访问
- ngx_http_gzip_module:压缩模块,对nginx返回的数据压缩,属于性能优化模块
- ngx_http_fastcgi_module:fastCGI模块,和动态应用相关的模块
- ngx_http_proxy_module:proxy代理模块
- ngx_http_upstream_module:负载均衡模块,可以实现网站的负载均衡功能及节点的健康检查
- ngx_http_rewrite_module:URL地址重写模块
- ngx_http_limit_conn_module:限制用户并发连接数及请求数模块
- ngx_http_limit_req_module:根据定义的key限制nginx请求过程的速率
- ngx_http_log_module:访问日志模块,以指定的格式记录nginx客户访问日志等信息
- ngx_http_auth_basic_module:web认证模块,设置web用户通过账号,密码访问nginx
- ngx_http_ssl_module:ssl模块,用于加密的http连接,如https
- ngx_http_stub_status_module:nginx基本访问状态信息模块
3、nginx主配置文件
[root@web01 ~]# cat /application/nginx/conf/nginx.conf #####nginx配置文件#号后面内容为默认
#user nobody; ###nginx默认权限用户,编译时已指定--user=nginx
worker_processes ; #####nginx进程数,默认为1,可根据服务器核心数修改,如单cpu4核心,可修改为4
#error_log logs/error.log; ###默认错误日志文件
#error_log logs/error.log notice; ####notice错误级别日志
#error_log logs/error.log info; ###info日志
#pid logs/nginx.pid; ####pid文件
events {
worker_connections ; ####nginx默认支持的最大连接数
}
http { ########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 ;
keepalive_timeout ; ####超时时间
#gzip on; ####支持gzip压缩
server { #####虚拟主机配置模块
listen ; ####监听80端口
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main; #####该虚拟主机访问日志
location / { ####location模块,
root html; #####站点数据文件目录
index index.html index.htm; ####默认网站首页
}
#error_page /.html; ####错误页面
# redirect server error pages to the static page /50x.html
#
error_page /50x.html; #####错误页面
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on
#
#location ~ \.php$ {
# root html;
# fastcgi_pass ;
# 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 { ######基于ip,端口的虚拟主机范例
# listen ;
# listen somename:;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server { #####基于ssl认证的范例
# listen 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;
# }
#}
}
Centos6 安装nginx的更多相关文章
- centos6安装nginx
1.获取官方的仓库地址 我们需要先访问nginx的官方网站,获取官方的仓库地址https://nginx.org/en/linux_packages.html#stable 新建/etc/yum.re ...
- 转载《centos6安装nginx最详细步骤》
出处:https://www.cnblogs.com/hltswd/p/6956264.html 第一步:在centos下面下载 nginx wget http://nginx.or ...
- centos6安装nginx最详细步骤
第一步:在centos下面下载 nginx wget http://nginx.org/download/nginx-1.2.9.tar.gz 解压 tar zxf nginx-1. ...
- centos6.3安装nginx
一般使用linux系统的不少网友可能都是直接使用一键安装包进行安装的,以前作者也这样,但是很多时候这些一键安装方便是方便但是可能在升级及其他很多地方不是很好,本文就说下在centos6.3安装ngin ...
- Centos6 下安装Nginx+Mysql+PHP
安装nginx https://segmentfault.com/a/1190000007928556 添加源 $ wget http://nginx.org/packages/centos/6/no ...
- 【CentOS6.5】安装nginx报错:No package nginx available. Error: Nothing to do
今天在给centos6.5安装nginx时候,提示报错No package nginx available. Error: Nothing to do, 后来百度一下,说缺少EPEL(epel是社区强 ...
- centos6.5编译安装nginx
系统64位 centos6.5 nginx官网:http://nginx.org/ 下载nginx源码包: wget http://nginx.org/download/nginx-1.6.2.ta ...
- centos6.5 安装nginx
安装之前先安装VMware tools(方便于从windows上拷贝文件到linux) 1. nginx安装环境 nginx是C语言开发,建议在linux上运行,本次使用Centos6.5作为安装环境 ...
- Centos6.6 编译安装nginx
一.基本环境 nginx 1.9版以后增加了一些新的特性,支持tcp负载均衡,不过这次还是用1.8.0,这里面有个memcached的代理模块,有时间再测试下 1.centos6.6 2.nginx1 ...
随机推荐
- bzoj 1499: [NOI2005]瑰丽华尔兹【dp+单调队列】
设f[a][i][j]为第a段时间结束时在(i,j)位置的最长滑行距离,转移很好想,就是分四个方向讨论,然后枚举这段时间的滑行长度取个max即可 但是这样是O(n^4)的,考虑优化 发现同一行或列,取 ...
- Survival on the Titanic (泰坦尼克号生存预测)
>> Score 最近用随机森林玩了 Kaggle 的泰坦尼克号项目,顺便记录一下. Kaggle - Titanic: Machine Learning from Disaster On ...
- SpringBoot项目docker化
前言 有很多种方案构建Docker镜像,包括Dockerfile构建.maven插件构建,这里我使用了最简单的Dockerfile构建的. 一.安装Docker 我的虚拟机系统是CentOS7,需要是 ...
- Golang bash脚本自动创建一个go工程
原作者的代码里面,存在智能引号问题,所以他的代码并不能正常运行: 这个是我微调后的版本. 代码如下: #!/bin/bash #————————————– # Module : mk_go_pro.s ...
- Unix\Linux | 总结笔记 |文件系统_shell重定向
输入重定向< 从文件中获得命令需要的输入数据,适合数据源已经定义好,可重复使用 #显示文件test.txt的内容 cat < tesxt.txt #统计文件test.txt中的行数 单词数 ...
- “玲珑杯”第七届郑州轻工业学院ACM程序设计大赛 ------- D:社交网络
题目链接: http://acm.zzuli.edu.cn/problem.php?cid=1099&pid=3 题目大意: 国语题目,题意显而易见, 解题思路: 只需要对每一个节点进行假设, ...
- _bzoj2038 [2009国家集训队]小Z的袜子(hose)【莫队】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2038 裸的莫队,注意要先移动右端点再移动左端点. #include <cstdio&g ...
- 32位Oracle10g在64位CentOS下安装失败记录
环境信息:Alibaba Cloud Elastic Compute Service,CentOS Linux release 7.4.1708 (Core),16C/64GB. 使用32位Oracl ...
- C# winform与Javascript的相互调用[转]
原文链接<html> <head> <meta http-equiv="Content-Language" content="zh-cn&q ...
- java中的位预算
public class Demo { public static void main(String[] args) { byte num1 = 3; byte num2 = 5; /*位预算 *nu ...