一、nginx介绍及安装

一、nginx简介:

Nginx是一个自由、开源、高性能及轻量级的http服务器及反向代理服务器。Nginx以其高性能、稳定、功能丰富、配置简单及占用系统资源少而著称。Nginx 超越 Apache 的高性能和稳定性,使得国内使用 Nginx 作为 Web 服务器的网站也越来越多。

注:nginx和apache各有优缺点,总体而言,静态和反向代理,优先选用nginx。

二、安装nginx:

1.系统平台centos 6.5:

2.安装依赖包,否则无法编译安装:

yum groupinstall -y "Development tools" "Server Platform Development" "Desktop Platform Development"
yum install -y pcre-devel

1)创建用户nginx和组nginx,实现以用户nginx运行nginx进行:

[[email protected] ~]# groupadd -r nginx    #nginx需要调用1000以下的端口,需要系统用户
[[email protected] ~]# useradd -r -g nginx nginx
[[email protected] ~]# id nginx
uid=496(nginx) gid=493(nginx) groups=493(nginx)

2)解压nginx安装包,安装文件可以在www.nginx.org 下载安装文件:

[[email protected] ~]# ls
anaconda-ks.cfg  install.log         nginx-1.9.3.tar.gz  temp.text  while.py
harlequin.vim    install.log.syslog  README.md           tet
[[email protected] ~]# tar xf nginx-1.9.3.tar.gz
[[email protected] ~]# ls
anaconda-ks.cfg  install.log         nginx-1.9.3         README.md  tet
harlequin.vim    install.log.syslog  nginx-1.9.3.tar.gz  temp.text  while.py
[[email protected] ~]# cd nginx-1.9.3
[[email protected] nginx-1.9.3]# mkdir -pv /var/tmp/nginx/client
mkdir: created directory `/var/tmp/nginx‘
mkdir: created directory `/var/tmp/nginx/client‘
[[email protected] nginx-1.9.3]# ./configure >   --prefix=/usr/local/nginx \
>   --sbin-path=/usr/local/nginx/sbin/nginx >   --conf-path=/etc/nginx/nginx.conf >   --error-log-path=/var/log/nginx/error.log >   --http-log-path=/var/log/nginx/access.log >   --pid-path=/var/run/nginx/nginx.pid  >   --lock-path=/var/lock/nginx.lock >   --user=nginx >   --group=nginx >   --with-http_ssl_module >   --with-http_flv_module >   --with-http_stub_status_module >   --with-http_gzip_static_module >   --http-client-body-temp-path=/var/tmp/nginx/client/ >   --http-proxy-temp-path=/var/tmp/nginx/proxy/ >   --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ >   --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi >   --http-scgi-temp-path=/var/tmp/nginx/scgi >   --with-pcre

选项


说明


--prefix=<path>


指定nginx安装路径,默认是在/usr/local/nginx


--sbin-path=<path>


指定nginx可执行文件安装路径,默认安装在<prefix>/sbin/nginx


--conf-path=<path>


指定默认的nginx.conf路径,默认是在<prefix>/conf/


--error-log-path=<path>


在nginx.conf下未指定error_log情况下,指定默认的错误日志路径


--http-log-path=<path>


在nginx.conf下未指定http_log情况下,指定默认的错误日志路径


--pid-path=<path>

在nginx.conf未指定pid指令的情况下,指定nginx.pid路径
--lock-path=<path> 指定nginx.lock路径
--user=<user> 指定nginx服务运行者,未指定则默认为nobady
--group=<group> 指定nginx服务运行者,未指定则默认为nobady
--with-http_ssl_module 启用ssl,nginx就可以支持https,但是系统必须有openssl库
--with-http_flv_module 启用flv模块
--with-http_stub_status_module 启用Server Status页
--with-http_gzip_module 禁用gzip模块,默认是启用的,但是需要zlib库
--http-client-body-temp-path=<path> 存放http方问客户端请求报文的临时文件路径,默认不存在,需要提前创建
--http-proxy-temp-path=<path> 启用proxy模块,指定http代理临时文件路径,默认不存在,需要提前创建
--http-fastcgi-temp-path=<path> 启用http的fastcgi模块,指定存放fastcgi模块临时文件的路径,默认不存在,需要提前创建
--http-uwsgi-temp-path=<path> 启用http的uwsgi模块,指定存放uwsgi模块临时文件的路径,默认不存在,需要提前创建
-with-pcre 指定pcre库,需提前安装pcre-devel
--http-scgi-temp-path=<path> 启用http的scgi模块,指定存放scgi模块临时文件的路径,默认不存在,需要提前创建
运行make && make install

3)创建服务脚本:

vim /etc/rc.d/init.d/nginx,写入如下脚本:(对脚本做一下说明,有些路径是根据上面configer的选项书写的)

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse # proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# pidfile: /var/run/nginx/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
configtest || return $?
stop
start
}

reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}

force_reload() {
restart
}

configtest() {
$nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
status $prog
}

rh_status_q() {
rh_status >/dev/null 2>&1
}

case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
给脚本添加权限:
chmod +x /etc/rc.d/init.d/nginx
添加开机启动:
chkconfig –add nginx
chkconfig nginx on

4)添加环境变量:
# echo "PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile (永久生效)

#export PATH=$PATH:/usr/local/nginx/sbin (当前生效)

5)测试并启动:

启动之前先,通过nginx -t测试

[[email protected] nginx-1.9.3]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[[email protected] nginx-1.9.3]# service nginx start
Starting nginx:                                            [  OK  ]

3.网站访问nginx,查看服务器ip地址,浏览器直接输入对应ip地址,nginx默认端口80.

注:输入ip,没有显示,请查看是否iptables开启。

关闭iptables:service iptables stop

时间: 2024-07-31 15:08:02

一、nginx介绍及安装的相关文章

Nginx介绍及安装配置

Nginx介绍 如果听说过Apache软件那么对于Nginx也会很快就熟悉的和Apache一样nginx是开源的支持高性能高并发的WWW服务.代理服务软件以及电子邮件代理服务器并在一个BSD-like协议下发行由俄罗斯Igor Sysoev所开发开始供俄国大型的入口网址及搜索引擎Rambler使用. nginx占有内存小并发能力强特别是静态资源且功能丰富而流行起来. 从软件的功能应用方面Nginx不但是一个优秀的Web服务软件还可以具有反向代理负载均衡能和缓存服务功能.代理方面类似专业的LVS负

Nginx 介绍和安装

Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了. Igor 将源代码以类 BSD 许可证的形式发布.尽管还是测试版,但是,Nginx 已经因为它的稳定性.丰富的功能集.示例配置文件和低系统资源的消耗而闻名了. 根据最新一期(08 年 6 月份)的 NetCraft 调

nginx介绍与安装

Nginx介绍 Nginx官网 nginx.org 一般使用稳定版stable version has been released.应用场景:web服务.反向代理.负载均衡 安装nginx 下载与解压 cd /usr/local/src/ wget http://nginx.org/download/nginx-1.12.2.tar.gz tar zxvf nginx-1.12.2.tar.gz 编译与安装 cd /usr/local/src/nginx-1.12.2/ ./configure

12.Nginx介绍,安装,配置默认虚拟主机,重定向

[toc] 12.5 Nginx介绍 官网:nginx.org 因为nginx处理静态文件的能力要比apache好很多,所以很多企业在建站的时候一般都是用java写的,然后会选择tomcat,但是tomcat处理静态文件的能力不是太好就会叠加选择nginx. nginx特点: 体积小 处理能力强 并发高 可扩展性好 Nginx应用场景: web服务 反向代理 负载均衡 Nginx著名分支,淘宝基于Nginx开发的Tengine,使用上和Nginx一致,服务名,配置文件名都一样,和Nginx的最大

Nginx 的编译安装和URL地址重写

本文转自:http://www.178linux.com/14119#rd?sukey=ecafc0a7cc4a741b573a095a3eb78af6b4c9116b74d0bbc9844d8fc5e8b50b3fc807541ae53fd06c67ac4f4adaae6981 在此只是做个笔记给自己看的. Nginx专题: 从编译安装到URL重写 前言 环境介绍 Nginx介绍 编译安装Nginx 配置文件解释 main和event{}的配置 http{}的基本配置 配置Nginx 搭建一个

LNMP架构介绍、MySQL安装、PHP安装、Nginx介绍

LNMP架构介绍 LNMP:linux+nginx+mysql+php的架构:php的动态处理交给php-fpm(127.0.0.1:9000),静态处理直接由nginx处理 工作模式: 1.在lamp中php作为独立的服务(php-fpm)存在 2.nginx支持高并发,动态请求转给php-fpm MySQL安装 请查看:http://jacksoner.blog.51cto.com/5802843/1979858 PHP安装(php-fpm) 1.[[email protected] pac

LNMP架构结介绍,MySQL和PHP的安装以及Nginx介绍

一.LNMP架构结介绍 LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构.Nginx中的PHP是以fastcgi的方式结合Nginx的,可以理解为Nginx代理了PHP的fastcgi. 详细介绍可参考:http://blog.csdn.net/u013592371/article/details/73729892 二.LNMP架构-安装MySQL LNMP中MySQL的安装步骤与LAMP中安装一样,这里简单写一下安装过程: [email protected]

lnmp架构介绍,mysql,php安装,Nginx介绍

lnmp架构介绍 MySQL安装 1.首先下载软件包 [[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz --2018-02-26 21:12:00-- http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz 正在解析主

12.1-12.5 LNMP架构介绍,MySQL安装,PHP安装,Nginx介绍

十二周一次课(4月23日) 12.1 LNMP架构介绍 12.2 MySQL安装 12.3/12.4 PHP安装 12.5 Nginx介绍 扩展 Nginx为什么比Apache Httpd高效:原理篇 http://www.toxingwang.com/linux-unix/linux-basic/1712.html apache和nginx工作原理比较 http://www.server110.com/nginx/201402/6543.html mod_php 和 mod_fastcgi以及