Linux 6下安装编译安装Nginx的步骤
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,Linux 6下安装编译安装Nginx的步骤前言:Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。在高连接并发的情况下,Nginx是Apache服务器不错
千家信息网最后更新 2025年12月02日Linux 6下安装编译安装Nginx的步骤
Linux 6下安装编译安装Nginx的步骤
前言:
Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。在高连接并发的情况下,Nginx是Apache服务器不错的替代品:Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一。能够支持高达50,000个并发连接数的响应,而且内存开销极小。这也是Nginx广受欢迎的重要原因。本文演示了基于Linux 6下编译安装Nginx,供大家参考。
一、安装环境
# cat /etc/issueRed Hat Enterprise Linux Server release 6.3 (Santiago)Kernel \r on an \m# nginx -vnginx 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 greproot 33412 1 0 10:18 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.confnginx 33413 33412 0 10:18 ? 00:00:00 nginx: worker process[root@orasrv1 cache]# netstat -nltp|grep 80tcp 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 binarynginxd=/usr/sbin/nginx#path for nginx configurationnginx_config=/etc/nginx/nginx.conf#path for nginx pidnginx_pid=/var/run/nginx.pidRETVAL=0prog="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 1fi 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" instart) start ;;stop) stop ;;reload) reload ;;restart) stop start ;;status) status $prog RETVAL=$? ;;*) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1esacexit $RETVAL# chmod u+x /etc/init.d/nginx # service nginx startStarting nginx: [ OK ]# ps -ef|grep nginx |grep -v greproot 33534 1 0 10:33 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.confnginx 33535 33534 0 10:33 ? 00:00:00 nginx: worker process # service nginx stopStopping 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_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using --with-pcre=option../configure: error: the HTTP gzip module requires the zlib library.You can either disable the module by using --without-http_gzip_moduleoption, or install the zlib library into the system, or build the zlib librarystatically from the source with nginx by using --with-zlib= option.### 以上2个错误,请安装相应的依赖包,见本文第二部分:配置安装环境# /usr/sbin/nginx nginx: [emerg] getpwnam("nginx") failed### 需要创建nginx用户组及用户# /usr/sbin/nginxnginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (2: No such file or directory)### 需要创建对应的目录
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
环境
服务
配置
服务器
用户
编译
建议
支持
步骤
不错
极小
重要
下编
主机
内存
前言
原因
口号
常见
平台
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
web服务器配置和管理
游戏软件开发怎么学
服务器硬盘一点点的减少
广水软件开发
知网数据库总文献量
中宏保险 软件开发
服务器管理器仪表
300730网络安全
数据库创建函数实例
我的世界挖化石服务器
北京吸宠网络技术有限公司
河南天科网络技术
数据库管理方面知识
pme软件开发环境
网吧服务器如何复制客户
网络安全和信息化 指导思想
公安内网服务器管理
鄂州网络安全监测
上海网络安全监察部门
dayz切换服务器后数据消失
总参网络安全
未成年人网络安全状况
论文网络安全摘要
工业视频服务器
unturned服务器怎么锁车
服务器vga能连接笔记本吗
鄂州网络安全监测
x58高性能服务器
预防网络安全的主题班会内容
文明重启服务器管理