nginx 安装
来源:互联网 发布:中国大数据领军人物 编辑:程序博客网 时间:2024/06/13 05:46
Nginx 安装指南
环境参数
操作系统版本:
Linux version 2.6.32-220.el6.x86_64 (mockbuild@x86-004.build.bos.redhat.com)
(gcc version 4.4.5 20110214 (Red Hat 4.4.5-6) (GCC)
依赖条件:
gzip module requires zlib library
rewrite module requires pcre library
ssl support requires openssl library
推荐工具
tmux
secureCRT
winscp
安装
下载 [zlib-1.2.8.tar.gz]
sudo wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.8.tar.gz?download
下载 [pcre-8.33.tar.gz]
sudo wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
「可选」下载
下载 [nginx-1.4.2.tar.gz]
sudo wget http://nginx.org/download/nginx-1.4.2.tar.gz
解压文件
tar zxf zlib-1.2.8.tar.gz
tar zxf pcre-8.33.tar.gz
tar zxf nginx-1.4.2.tar.gz
移动文件到安装路径(示例中为/opt目录下)
sudo mv zlib-1.2.8 /opt
sudo mv pcre-8.33 /opt
sudo mv nginx-1.4.2 /opt
编译nginx
cd /opt/nginx-1.4.2/
./configure --prefix=/usr/local/ --sbin-path=/usr/local/sbin --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/run/nginx/client_body_temp --http-proxy-temp-path=/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/var/run/nginx/scgi_temp --with-pcre=../pcre-8.33 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-1.0.1e --with-ipv6 --with-http_ssl_module --with-http_gzip_static_module
参数说明
路径
--prefix=/usr/local/
--sbin-path=/usr/local/sbin
--conf-path=/etc/nginx/nginx.conf
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
临时文件
+ --http-client-body-temp-path=/var/run/nginx/client_body_temp
+ --http-proxy-temp-path=/var/run/nginx/proxy_temp
+ --http-fastcgi-temp-path=/var/run/nginx/fastcgi_temp
+ --http-uwsgi-temp-path=/var/run/nginx/uwsgi_temp
+ --http-scgi-temp-path=/var/run/nginx/scgi_temp
依赖
+ --with-pcre=../pcre-8.33
+ --with-zlib=../zlib-1.2.8
+ --with-openssl=../openssl-1.0.1e
功能模块
+ --with-ipv6
+ --with-http_ssl_module
+ --with-http_gzip_static_module
详情请参考
[Installation and compile-time options]
安装
make & make install
问题
nginx ssl 版本问题
安装openssl
下载openssl
1.sudo wget http://www.openssl.org/source/openssl-1.0.1e.tar.gz
解压
2.sudo tar -zxvf openssl-1.0.1e.tar.gz
3.sudo mv openssl-1.0.1e /opt/
安装
4.cd openssl-1.0.1e
sudo ./config --prefix=/usr/local/openssl
sudo ./config -t
sudo make depend
sudo make
sudo make test
sudo make install
5.cd /usr/local
In -s /openssl /ssl
6.动态库搜索路径
增加"/usr/local/lib"到你的"/etc/ld.so.conf",并执行ldconfig命令
cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/ssl/lib
同等操作如下
echo "usr/local/ssl/lib">>/etc/ld.so.conf
sudo ldconfig
(1)找不到ldconfig 命令 环境变量中添加
export PATH = $PATH:/sbin
7.export PATH = $PATH:/usr/local/ssl/bin
综上 可以 vi /etc/profile
export PATH = /usr/local/ssl/bin:/sbin:$PATH
# 创建用户,但不创建用户 home
useradd -M nginx
# 锁定用户,使用户无法通过 password 登录
usermod -L nginx
添加开机启动nginx
sudo vi /etc/init.d/nginx (输入下面的代码)
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/sbin/nginx (指向nginx 启动文件 在objs下面的MakeFile 里面会配置nginx make&make install 会生成nginx 的启动文件)
nginx_config=/etc/nginx/nginx.conf(指向你的配置地址)
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
:wq 保存并退出
设置文件的访问权限
chmod a+x /etc/init.d/nginx (a+x ==> all user can execute 所有用户可执行)
# 增加服务启动项
sudo chkconfig --add nginx
# 设置开机自动启动
sudo chkconfig --level 345 nginx on
sudo service nginx start stop restart
/etc/init.d/nginx status
/etc/init.d/nginx start stop restart
- nginx笔记:nginx安装
- Nginx-----源码安装nginx
- 【nginx】nginx的安装
- 安装Nginx
- nginx安装
- 安装 nginx
- 安装nginx
- 安装 Nginx
- nginx安装
- Nginx安装
- 安装Nginx
- 安装nginx
- nginx安装
- 安装nginx
- Nginx安装
- nginx安装
- nginx安装
- nginx 安装
- struts2怎么升级到2.3.15.1版本,Struts2升2.3.15.1后tomcat启动不了
- cat
- 关于android 百度地图api 无法定位
- mac使用技巧三则
- gdb调试
- nginx 安装
- KMP字符串模式匹配详解
- R linux安装
- Java的内存泄漏
- 笔记8:Color
- 老罗的ANDROID之旅---IPC学习笔记
- 年轻工程师挣高工资的奥秘
- 关于python中带下划线的变量和函数 的意义
- 合理的布局,绚丽的样式,谈谈Winform程序的界面设计