今天打算安装nginx,下面记录一下安装过程,以便以后参考,官网路径:http://nginx.org/ 所有历史版本包下载:http://nginx.org/download/
安装基本依赖包
Nginx 依赖 zlib zlib-devel gcc-c++ libtool openssl openssl-devel
安装命令:
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
参考进行安装:http://www.cnblogs.com/skynet/p/4146083.html
一、安装过程发现问题:
1、发现pcre需要下下来安装才可以,直接用yum install pcre 发现不行。
wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
解压缩pcre-xx.tar.gz包
进入解压缩目录,执行./configure
make & make install
nginx在配置的时候建议配置下面的模块:真实ip模块、gzip模块、ipv6模块(这个好像有问题,用不到暂时可以去掉)
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-ipv6
2、新建一个nginx用户安装发现不可以,最后切好root用户安装才行,后续估计需要研究一下。
启动: /usr/local/nginx/sbin/nginx
发现报:/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
解决方法:
ln -s /usr/local/lib/libpcre.so.1 /lib64
32位系统则:
ln -s /usr/local/lib/libpcre.so.1 /lib
注:
/usr/local/lib/libpcre.so.1 为prce安装后的文件地址
低版本prce对应的libpcre.so.1 为libpcre.so.0
参考http://blog.csdn.net/white__cat/article/details/37923087 解决上面问题。
查看Nginx的版本号:nginx -V
启动Nginx:service nginx start (一般是./nginx就启动了)
快速停止或关闭Nginx:nginx -s stop ( service nginx stop)
正常停止或关闭Nginx:nginx -s quit
配置文件修改重装载命令:nginx -s reload
查看windows任务管理器下Nginx的进程命令:tasklist /fi "imagename eq nginx.exe"
http://www.cnblogs.com/lixigang/articles/5130052.html
已安装nginx动态添加模块
说明:
已经安装好的nginx,需要添加一个未被编译安装的模块,需要怎么弄呢?
具体:
这里以安装第三方ngx_http_google_filter_module模块为例
nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so
1. 下载第三方扩展模块ngx_http_google_filter_module
# cd /data/software/
# git clone https://github.com/cuber/ngx_http_google_filter_module
2. 查看nginx编译安装时安装了哪些模块
# nginx -V
nginx version: nginx/1.8.0 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --add-module=/data/software/ngx_http_substitutions_filter_module 可以看出编译安装使用了--prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --add-module=/data/software/ngx_http_substitutions_filter_module这些参数。--add-module=/data/software/ngx_http_substitutions_filter_module是之前编译添加ngx_http_substitutions_filter_module模块时添加
3. 加入需要安装的模块,重新编译,如这里添加–add-module=/data/software/ngx_http_google_filter_module
# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --add-module=/data/software/ngx_http_substitutions_filter_module --add-module=/data/software/ngx_http_google_filter_module
# make //千万不要make install,不然就真的覆盖了
4. 替换nginx二进制文件:
# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
# cp ./objs/nginx /usr/local/nginx/sbin/
简单的nginx和tomcat代理配置
upstream icp_admin_server_1{
server 127.0.0.1:8082 max_fails=1 fail_timeout=10s;
}
server{
listen 80;
server_name admin.baidu.cn;
access_log logs/admin.baidu.access.log;
error_log logs/admin.baidu.error.log;
location / {
#proxy_set_header Host $host; 网上说要配成$host,目前在proxy.conf里面配置的是$http_host;
proxy_pass http://icp_admin_server_1;
include proxy.conf;
}
}
proxy.conf配置引用文件:
proxy_redirect off;
#proxy_set_header Host $host:$server_port;
proxy_set_header Host $http_host;
proxy_set_header PROXY-Host $http_host;
proxy_set_header PROXY-Port $http_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Scheme $scheme;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 990;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
下面是tomcat里面的conf目录server.xml配置,其实就加了标红一条即可。
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context docBase="/usr/local/apache-tomcat-7.0.82/webapps/Icpback" path="" ></Context>
</Host>
直接输入域名admin.baidu.cn就可以访问tomcat里面的Icpback项目,如果有多个项目,那么上面的path就必须配置/Icpback,而且域名访问变成admin.baidu.cn/Icpback
如果不生效,把Host name="localhost"改成name="admin.baidu.cn"
上面的配置导致程序运行一段时间后,发现后台日志报:Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
后来经过研究,发现Context配置docBase目录也是webapps下的,所有导致项目重复部署,久而久之内存用完。
Context配置docBase目录必须改为不是webapps下就可以了。后来用<Context docBase="/usr/local/apache-tomcat-7.0.82/myapp/Icpback" path="" ></Context>
改前和改后对比catalina.out日志就会发现问题。
参考:http://blog.csdn.net/u012554102/article/details/50409452