Linux 6下安装编译安装Nginx的步骤
作者:Leshami 发布时间:2022-05-08 17:11:18
标签:Linux,安装Nginx
Linux 6下安装编译安装Nginx的步骤
前言:
Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。在高连接并发的情况下,Nginx是Apache服务器不错的替代品:Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一。能够支持高达50,000个并发连接数的响应,而且内存开销极小。这也是Nginx广受欢迎的重要原因。本文演示了基于Linux 6下编译安装Nginx,供大家参考。
一、安装环境
# cat /etc/issue
Red Hat Enterprise Linux Server release 6.3 (Santiago)
Kernel \r on an \m
# nginx -v
nginx version: nginx/1.8.0
二、配置安装环境
###为简化安装及配置,此处关闭了防火墙,生产环境建议开启
# service iptables stop
# chkconfig iptables off
# vi /etc/selinux/config
SELINUX=disabled
###创建用户及组
#groupadd -r nginx
#useradd -s /sbin/nologin -g nginx -r nginx
###安装环境依赖包 http://nginx.org/en/linux_packages.html
# yum install pcre-devel zlib-devel openssl openssl-devel gcc gcc-c++
三、编译及安装Nginx
# cd /tmp/
# tar -xvf nginx-1.8.0.tar.gz
# cd /nginx-1.8.0
# ./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/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.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=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-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_spdy_module \
--with-ipv6
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: "/etc/nginx"
nginx binary file: "/usr/sbin/nginx"
nginx configuration prefix: "/etc/nginx"
nginx configuration file: "/etc/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/var/cache/nginx/client_temp"
nginx http proxy temporary files: "/var/cache/nginx/proxy_temp"
nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp"
nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp"
nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"
###如果apache httpd服务启动,建议先停止或更改端口号
# service httpd stop
# mkdir -p /var/cache/nginx/{client_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp}
# make && make install
###启动nginx
# /usr/sbin/nginx -c /etc/nginx/nginx.conf
# ps -ef|grep nginx|grep -v grep
root 33412 1 0 10:18 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 33413 33412 0 10:18 ? 00:00:00 nginx: worker process
[root@orasrv1 cache]# netstat -nltp|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 33412/nginx
[root@orasrv1 cache]#
四、配置nginx为系统服务
vi /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# Author : Leshami
# Blog : http://blog.csdn.net/leshami
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /etc/nginx/nginx.conf
#path for nginx binary
nginxd=/usr/sbin/nginx
#path for nginx configuration
nginx_config=/etc/nginx/nginx.conf
#path for nginx pid
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
# chmod u+x /etc/init.d/nginx
# service nginx start
Starting nginx: [ OK ]
# ps -ef|grep nginx |grep -v grep
root 33534 1 0 10:33 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 33535 33534 0 10:33 ? 00:00:00 nginx: worker process
# service nginx stop
Stopping nginx: [ OK ]
# chkconfig --add nginx
# chkconfig nginx on
五、安装过程中的常见故障
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
### 以上2个错误,请安装相应的依赖包,见本文第二部分:配置安装环境
# /usr/sbin/nginx
nginx: [emerg] getpwnam("nginx") failed
### 需要创建nginx用户组及用户
# /usr/sbin/nginx
nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (2: No such file or directory)
### 需要创建对应的目录
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
来源:http://blog.csdn.net/leshami/article/details/51324959
0
投稿
猜你喜欢
- 留白是纸质媒体经常使用的一个技巧。例如报纸版面在配置的时候,并非填充的越满越好,适当的留些空白,不仅美化了版面,而且保证了优质的用户体验。在
- 不知道多久以前,上网是被作为一门技术来看待的,甚至曾经有人把上网和开车一起看成21世纪必须掌握的两门技术之一,internet是神秘的,是高
- 启用并配置文件服务Windows Server 2003的管理工具中有一项功能叫做“管理您的服务器”,启动该工具之后,可以看到当前服务器上启
- 接触JSP服务器的人基本上都是从JSP的安装开始的,因为JSP不像ASP那样几乎不存在什么安装过程,也不像PHP那样有一个自动安装的程序包,
- 一个系统管理员可能会同时管理着多台服务器,这些服务器也许会放在不同的地方。要亲自一台一台的去访问来管理它们显然不是最好的方法,通过远程控制的
- 国庆期间,华谊公司集结旗下众多一线明星拍摄的献礼影片《风声》,自首映以来票房一路高升,好评如潮。为了延续影片的精彩,我突发奇想,用&
- 添加硬盘到虚拟机 并实现自动挂载 (https://www.jb51.net/article/135432.htm)完成挂载硬盘后,开始以下
- Godaddy主机的Update Contact Information部分使你能够更新域名的联系信息。私人或者在设置中的域名联系信息无法更
- 笔者公司共有10台Web服务器,使用Redhat Linux 9作为操作系统,分布在全国各大城市,主要为用户提供HTTP服务。曾经有一段时间
- 四、修改pam[root@localhostpam_mysql]#cd/etc/pam.d[root@localhostpam.d]#cp/
- 环境:CentOS Linux release 7.3.1611 (Core)3.10.0-514.16.1.el7.x86_641.安装J
- 博客上经常出现一些Google的垃圾广告,诸如“减肥、战痘之类”,这些垃圾广告不仅粗制滥造,视觉污染不说,还影响经济收入。也尝试过在“AdS
- 这几天一华尔街日报专栏作家Mark Penn的一篇《美国新职业“专职博客”》赢得不少关注。这篇文章的原文在这里。我稀里糊涂博客五年,对这个话
- 国内知名的通用建站软件开发商phpwind今天再次推送新产品应用淘链接,据官方介绍,通过淘链接这一APP应用,把淘宝商品链接转换为佣金结算的
- Windows Server 2008正在逐渐向我们走来,随着最近其第一个RC版的问世,意味着它真正发布的时刻已经不会让我们等待太长的时间。
- 一次在网上闲逛,突然看到论坛有一条消息说有一种方法,可以让已经关闭的Linux机器继续运行ipchains,并且让这台机器继续实现防火墙的功
- 有时为了工作需要我们要在苹果系统Mac OS上安装相应的软件进行测试,而平时用的最多又是Windows操作系统,总不能为了一两次测试学习而去
- 中文分词是将一句话或一个短语按照日常阅读习惯进行机械分解。英文是以词为单位的,词和词之间是靠空格隔开,而中文是以字为单位,句子中所有的字连起
- Redis 是一个开源的使用 ANSI C 语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value 的 NoSQL 数据库,并
- 在互联网web1.0时代,常用的网络营销有:搜索引擎营销、电子邮件营销、即时通讯营销、BBS营销、病毒式营销;但随着互联网发展至web2.0