模块依赖性Nginx需要依赖下面3个包
1. gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ )
2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ )
3. ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ )
Nginx包下载: http://nginx.org/en/download.html
依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包.
图解教程
第一步: 下载安装所需包
openssl-fips-2.0.7.tar.gz
zlib-1.2.8.tar.gz
pcre-8.35.tar.gz
nginx-1.7.3.tar.gz
第二步:依次安装openssl-fips-2.0.7.tar.gz, zlib-1.2.8.tar.gz, pcre-8.35.tar.gz, nginx-1.7.3.tar.gz
1.安装openssl-fips-2.0.7.tar.gz
[root@localhost mrms]# tar -zxvf openssl-fips-2.0.7.tar.gz
[root@localhost mrms]# cd openssl-fips-2.0.7
[root@localhost openssl-fips-2.0.7]# ./config
[root@localhost openssl-fips-2.0.7]# make
[root@localhost openssl-fips-2.0.7]# make install
2.安装zlib-1.2.8.tar.gz
[root@localhost mrms]# tar -zxvf zlib-1.2.8.tar.gz
[root@localhost mrms]# cd zlib-1.2.8
[root@localhost zlib-1.2.8]# ./configure
[root@localhost zlib-1.2.8]# make
[root@localhost zlib-1.2.8]# make install
3.安装pcre-8.35.tar.gz
[root@localhost mrms]# tar -zxvf pcre-8.35.tar.gz
[root@localhost mrms]# cd pcre-8.35
[root@localhost pcre-8.35]# ./configure
[root@localhost pcre-8.35]# make
[root@localhost pcre-8.35]# make install
4.安装 nginx-1.7.3.tar.gz
[root@localhost mrms]# tar -zxvf nginx-1.7.3.tar.gz
[root@localhost mrms]# cd nginx-1.7.3
[root@localhost nginx-1.7.3]# ./configure --with-pcre=../pcre-8.35 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-fips-2.0.7
[root@localhost nginx-1.7.3]# make
[root@localhost nginx-1.7.3]# make install
至此Nginx的安装完成!
第三步:检测是否安装成功
[root@localhost nginx-1.7.3]# cd /usr/local/nginx/sbin
[root@localhost sbin]# ./nginx -t
出现如下所示提示,表示安装成功
[root@localhost sbin]# ./nginx
查看端口
[root@localhost sbin]# netstat -ntlp
结果如下
第四步:配置nginx,conf
[root@mobileSQL ~]# vi /usr/local/nginx/conf/nginx.conf
在nginx.conf中添加
http {
#...
include /etc/nginx/conf.d/*.conf;
#...
}
这里将其它不涉及的内容忽略掉了。上面的代码的作用是包含在conf.d目录下的所有.conf文件。 因此,你可以把特别的配置写到conf.d目录下的某个文件,如: uliweb.conf
。内容 可以是:
server {
listen 80;
location / {
include uwsgi_params;
#proxy_pass localhost:8000;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_pass unix:///tmp/uwsgi.sock;
}
}
上面就把Nginx设置好了。如果要使用Nignx提供静态文件服务,可以在上面的server中添加:
location ~ ^/static/ {
root /your/path/to;
}
二:安装uwsgi
1、编译uWSGI
uWSGI下载地址:http://projects.unbit.it/downloads/
tar xzvf uwsgi-1.2.tar.gz
cd uwsgi-1.2
make -j 8
#或者使用python编译
python uwsgiconfig.py --build
#复制生成的可执行文件uwsgi到/usr/sbin/目录下
cp uwsgi /usr/sbin/
也可以使用pip install uwsgi安装
2、测试uwsgi是否可用
测试脚本test.py
#!/usr/bin/python
def application(env,start_response):
start_response('200 OK',[('Content_Type','text/html')])
return "Congraduation!!! uWSGI Testing OK!!!
#启动web server
uwsgi --http :9090 --wsgi-file test.py
浏览器输入IP:端口:192.168.1.99:9090
可以看到”Congraduation!!! uWSGI Testing OK!!!”
3、命令行配置uwsgi
创建webstart.sh文件,拷贝以下脚本
#!/bin/bash
sockfile=/tmp/uwsgi.sock
projectdir=/your/project/path
logfile=/opt/web/logs/uwsgi.log
if [ $1 = start ];then
psid=`ps aux|grep "uwsgi"|grep -v "grep"|wc -l`
if [ $psid -gt 2 ];then
echo "uwsgi is running!"
exit 0
else
uwsgi -s $sockfile --chdir $projectdir -w wsgi_handler -p 10 -M -t 120 -T -C -d $logfile
fi
echo "Start uwsgi service [OK]"
elif [ $1 = stop ];then
killall -9 uwsgi
echo "Stop uwsgi service [OK]"
elif [ $1 = restart ];then
killall -9 uwsgi
uwsgi -s $sockfile --chdir $projectdir -w wsgi_handler -p 10 -M -t 120 -T -C -d $logfile
echo "Restart uwsgi service [OK]"
else
echo "Usages: sh start.sh [start|stop|restart]"
fi