Nginx依赖三个包
gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ ) zlib-1.2.8.tar.gz
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8
./configure
make&make install
2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ ) pcre-8.21.tar.gz
安装PCRE库
wget ftp:///pub/software/programming/pcre/pcre-8.21.tar.gz
tar -zxvf pcre-8.21.tar.gz
cd pcre-8.21
./configure
make&make install
3. ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ ) openssl-1.0.1.tar.gz
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar -zxvf openssl-1.0.1c.tar.gz
./config
make&make install
注:可以使用一键安装依赖包 yum -y groupinstall "Development Tools" "Development Libraries"
4.安装nginx
wget http://nginx.org/download/nginx-1.2.8.tar.gz
tar -zxvf nginx-1.2.8.tar.gz
cd nginx-1.2.8
./configure --prefix=/usr/local/nginx \--conf-path=/etc/nginx/nginx.conf \
--sbin-path=/usr/sbin/nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_p_w_picpath_filter_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gzip_static_module \
--with-http_concat_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_sysguard_module \
--with-backtrace_module \
--with-http_stub_status_module \
--with-http_upstream_check_module
#定义编译参数#
make&make install
5.编辑nginx.conf文件#需要根据具体情况编写#
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65536;
events
{
use epoll;
worker_connections 65536;
}
http
{
include mime.types;
default_type application/octet-stream;
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
open_file_cache max=65536 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
port_in_redirect off;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_vary on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 16k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
server
{
listen 80;
server_name #只需更改 server_name 为对应的网站域名即可#
index index.html index.htm;
error_log
access_log
if ($host ~* ^()$) {
rewrite ^/(.*)$
break;
}
rewrite ^(.*)\;(.*)$ $1 last;
location ~ \.( jsp|do|html|action|tpl|eot|svg|page|woff|ttf)$ {
proxy_pass http://127.0.0.1:8564;
proxy_redirect off;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
6.nginx安装完毕,启动nginx。service nginx start(如果找不到命令,可能是nginx安装版本的问题没有启动脚本。copy一个脚本过来,就可以使用命令了。当然还有别的命令进行重启,开启,关闭)。
7.chkconfig nginx on(将nginx添加到开机启动,
注:proxy_pass http://127.0.0.1:8564 要和 tomcat 端口保持一致。
8.nginx相关命令:
/usr/local/nginx/nginx -t 检查nginx配置文件
/usr/local/nginx/nginx -s reload 重新加载配置文件(不停止服务)
/usr/local/nginx/sbin/nginx –s reload 重启9.Nginx编译的参数
–prefix #nginx安装目录,默认在/usr/local/nginx–pid-path #pid文件位置,默认在logs目录
–lock-path #lock文件位置,默认在logs目录
–with-http_ssl_module #开启HTTP SSL模块,以支持HTTPS请求。
–with-http_dav_module #开启WebDAV扩展动作模块,可为文件和目录指定权限
–with-http_flv_module #支持对FLV文件的拖动播放
–with-http_realip_module #支持显示真实来源IP地址
–with-http_gzip_static_module #预压缩文件传前检查,防止文件被重复压缩
–with-http_stub_status_module #取得一些nginx的运行状态
–with-mail #允许POP3/IMAP4/SMTP代理模块
–with-mail_ssl_module #允许POP3/IMAP/SMTP可以使用SSL/TLS
–with-pcre=../pcre-8.21 #注意是未安装的pcre路径
–with-zlib=../zlib-1.2.8 #注意是未安装的zlib路径
–with-debug #允许调试日志
–http-client-body-temp-path #客户端请求临时文件路径
–http-proxy-temp-path #设置http proxy临时文件路径
–http-fastcgi-temp-path #设置http fastcgi临时文件路径
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #设置uwsgi 临时文件路径
–http-scgi-temp-path=/var/tmp/nginx/scgi #设置scgi 临时文件路径
















