转:CentOS 6.5 nginx
CentOS 6.5安装及简单配置Nginx
一、准备事项
(1) 因为nginx需要访问80端口所以请先关闭或者开放防火墙端口,和selinux。
参考命令
关闭防火墙:
[root@local ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@local ~]# service iptables save
关闭selinux:
[root@local ~]# setenforce 0
[root@local ~]# vim /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
(2) 如果用到域名请自行构建DNS服务
二、安装
(1) 因为nginx的运行需要安装pcre、zlib等软件包,因此我们进行安装
Pcre=Pcre Compatible Regular Expressions(中文pcre兼容正则表达式)
Yum配置请参考: http://www.linuxidc.com/Linux/2015-11/125332.htm
[root@local ~] yum -y install pcre* zlib* #或者进行编译安装
[root@local ~]# useradd -M -s /sbin/nologin nginx #创建nginx服务
启动用户
(3) 编译安装nginx,下载地址:http://nginx.org/en/download.html 此次安装为最新稳定版nginx-1.8.0
[root@local ~]# tar zxf nginx-1.8.0.tar.gz
[root@local ~]# cd nginx-1.8.0
[root@local nginx-1.8.0]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[root@local nginx-1.8.0]# ./configure --user=nginx --group=nginx
--prefix=/application/nginx-1.8.0 --with-http_stub_status_module
--with-http_ssl_module #./configure –help 参数详解
[root@local nginx-1.8.0]# make
[root@local nginx-1.8.0]# make install
(4) 制作软连接
[root@local nginx-1.8.0]#ln –a /application/nginx-1.8.0/
/application/nginx
(5) 基本使用
#语法检查
[root@local nginx-1.8.0]# /application/nginx/sbin/nginx –t
nginx: the configuration file /application/nginx-1.8.0/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.8.0/conf/nginx.conf test is successful
#启动服务
[root@local nginx-1.8.0]# /application/nginx/sbin/nginx
#端口检查
[root@local nginx-1.8.0]# netstat –lnt
#检查进程
[root@local nginx-1.8.0]# ps -ef | grep nginx #端口信息保存在
/application/nginx/logs/ nginx.pid 文件中
#通过端口查看占用进程
[root@local nginx-1.8.0]# lsof -i :80
#错误日志
/application/nginx/logs/error.log
三、编写nginx服务脚本
为了方便使用习惯,通过server 来启动、关闭、开启、重载nginx服务所以我们来编
写nginx的服务脚本(自己编写的脚本仅供参考!)
[root@local ~]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig: - 99 20
#description:Nginx Server Contorl Script
PROG="/application/nginx/sbin/nginx"
PIDF="/application/nginx/logs/nginx.pid"
ok=`echo -e "\e[1;31m [ok] \e[0m"`
no=`echo -e "\e[1;31m [no] \e[0m"`
detection=`/application/nginx/sbin/nginx -t 2>&1`
screen_1=`echo $detection | awk '{print $6,$7,$8}'`
screen_2=`echo $detection | awk '{print $13,$14,$15}'`
if [ "$screen_1" = "syntax is ok" ] && [ "$screen_2" = "test is successful" ];
then
case "$1" in
start)
$PROG
echo "Nginx Is starting state $ok"
;;
stop)
kill -s QUIT $(cat $PIDF)
echo "Nginx Is closing state $ok"
;;
restart)
$0 stop
$0 start
echo "Nginx Is to restart state $ok"
;;
reload)
kill -s HUP $(cat $PIDF)
echo "Nginx Is overloaded state $ok"
;;
*)
echo "Usage: $0 (start|stop|restart|reload)"
exit 1
esac
else
echo "Nginx check state $no "
echo "Please check the configuration file"
echo "$detection"
fi
exit 0
[root@local ~]# chmod +x /etc/init.d/nginx
[root@local ~]# chkconfig –add nginx #添加为系统服务
[root@local ~]# chkconfig nginx on
四、简单的nginx web站点
Nginx的默认站点目录,是安装目录下的html这里是(/application/nginx/html)
在主配置文件/application/nginx/conf/nginx.conf 中查看,对于重新部署web页面
只需将/application/nginx/html/中的index.html替换即可
主配置文件讲解
[root@local ~]# egrep -v "#|^$" /application/nginx/conf/nginx.conf
worker_processes 1; #指定Nginx开启的进程数
events { #设定Nginx的工作模式及连接数上线
worker_connections 1024;
}
http {
include mime.types; #主模块命令,实现对配置文件所有包含文件的设置
default_type application/octet-stream; #属于http核心模块命令,这里设
置类型为二进制流,也就是当文件类型未定义时使用这种方式,例如,没有配置PHP
环境时,nginx是不给予解析的,此时,用浏览器访问PHP文件就会出现下载窗口。
sendfile on; #用于高效文件传输模式
keepalive_timeout 65; 设置客户端请求头文件读取超时时间,如果超过这个时
间服务器会关闭该连接。
server { #定义虚拟主机开始的关键字
listen 80; #用于指定虚拟主机的服务端口
server_name localhost; 用于指定ip地址或者域名,多个域名用空格隔开
location / {
root html;
index index.html index.htm; #用于设定访问的默认首页
}
error_page 500 502 503 504 /50x.html;# 静态页面重定向服务器错误
页面,例如携程的网站崩溃出现的页面
location = /50x.html {
root html;
}
}
}
更多Nginx相关教程见以下内容:
CentOS 6.2实战部署Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm
使用Nginx搭建WEB服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm
搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm
CentOS 6.3下Nginx性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm
CentOS 6.3下配置Nginx加载ngx_pagespeed模块 http://www.linuxidc.com/Linux/2013-09/89657.htm
CentOS 6.4安装配置Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm
Nginx安装配置使用详细笔记 http://www.linuxidc.com/Linux/2014-07/104499.htm
Nginx日志过滤 使用ngx_log_if不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm
Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-12/125870.htm
转:CentOS 6.5 nginx的更多相关文章
- CentOS7 编译安装 Nginx (实测 笔记 Centos 7.0 + nginx 1.6.2)
环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...
- CentOS 6.6 nginx PHP 配置
/************************************************************************* * CentOS 6.6 nginx PHP 配置 ...
- CentOS 6.6 nginx install
/************************************************************************* * CentOS 6.6 nginx instal ...
- 删:Centos 7安装Nginx 1.8
[CentOS 7] 安装nginx! 首先进行 nginx yum Nginx安装记录 注意:如果用源码安装,nginx配置时需要指定--with-pcer对应的压缩包路径,如果使用二进制安装不需要 ...
- linux/centos下安装nginx(rpm安装和源码安装)详细步骤
Centos下安装nginx rpm包 ...
- CentOS下安装Nginx并添加nginx_upload_module
安装前,最好能保证依赖的系统软件已经升级. yum update CentOS上安装Nginx,如果只是简单安装,不附加其他第三方模块,一句话可以搞定: yum install nginx ...
- CentOS 7安装nginx
CentOS 7安装nginx 参考网上其他文章做的 安装Nginx 我们从nginx官方的RPM源来安装一个预构建的稳定版本的nginx包. rpm --import http://nginx.or ...
- CentOS 6.5 + Nginx 1.8.0 + PHP 5.6(with PHP-FPM) 负载均衡源码安装
CentOS 6.5 + Nginx 1.8.0 + PHP 5.6(with PHP-FPM) 负载均衡源码安装 http://www.cnblogs.com/ppoo24/p/4918288.ht ...
- CentOS 6.2+Nginx+Nagios,手机短信和qq邮箱提醒
http://chenhao6.blog.51cto.com/6228054/1323192 标签:软件包 配置文件 nagios 服务端 监控 原创作品,允许转载,转载时请务必以超链接形式标明文章 ...
- 在CentOS 上搭建nginx来部署静态页面网站
在centOs 上搭建nginx来部署静态页面网站 一.部署服务器环境 nginx:轻量级.高性能的HTTP及反向代理服务器,占用内存少,并发能力强,相比老牌的apache作为web服务器,性能更加卓 ...
随机推荐
- ADSL_自动拨号源码(Delphi),已经测试通过
下载地址: http://files.cnblogs.com/lwm8246/ADSL_%E8%87%AA%E5%8A%A8%E6%8B%A8%E5%8F%B7.rar
- 将Komodo Edit打造成Python开发的IDE
Komodo Edit 支持Python 界面清爽, 将Komodo Edit 设置成Python的IDE,具体操作方法如下: 先添加自定义命令. 再设置命令行参数 设置高级选项 设置快捷键 完成.
- sql查询平均下单时间
SQL查询订单平均审核时长 今天在写一个sql,需求是算一个订单在执行状态中的各个节点的时长 比如在订单中,状态0为开始接单,状态3为已经审核,那么现在需要计算每个客服的平均审核时长 像图中所示:这个 ...
- [Noip2016]愤怒的小鸟(状压DP)
题目描述 题意大概就是坐标系上第一象限上有N只猪,每次可以构造一条经过原点且开口向下的抛物线,抛物线可能会经过某一或某些猪,求使所有猪被至少经过一次的抛物线最少数量. 原题中还有一个特殊指令M,对于正 ...
- 小白日记1:kali环境Wpscan渗透Wordpress
一.什么是Wpscan?什么是Wordpres? 1.Wpscan WPScan是一款针对wordpress的安全扫描软件:可以扫描出wordpress的版本,主题,插件,后台用户以及爆破后台用户密码 ...
- 1,VMware与Centos系统安装
选择性 pc可以选择 -纯系统 Linux/windows -双系统 Windows+Linux -虚拟化技术 Windows+vmware workstation 服务器 -物理机纯系统 -物理机+ ...
- powershell设置SS代理
$env:HTTPS_PROXY="http://127.0.0.1:1080" $env:HTTP_PROXY="http://127.0.0.1:1080"
- 剑指Offer - 九度1513 - 二进制中1的个数
剑指Offer - 九度1513 - 二进制中1的个数2013-11-29 23:35 题目描述: 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 输入: 输入可能包含多个测试样例. ...
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目1
2014-04-23 17:32 题目:请设计一个数据结构来模拟一副牌,你要如何用这副牌玩21点呢? 解法:说实话,扑克牌的花样在于各种花色.顺子.连对.三带一.炸弹等等,如果能设计一个数据结构,让判 ...
- js点击重置按钮重置表单
<html><head><script type="text/javascript">function formReset(){document ...