参考:http://www.jsprun.net/thread-16889-1-1.html
http://jayghost.iteye.com/blog/1465411
1、上传nginx-0.7.63.tar.gz至/usr/local
2、执行如下命令解压nginx:
#cd /usr/local
#tar zxvf nginx-0.7.63.tar.gz
3、编译安装nginx
#cd nginx-0.7.63
#./configure --with-http_stub_status_module --with-http_ssl_module #启动server状态页和https模块
执行完后会提示一个错误,说缺少PCRE library 这个是HTTP Rewrite 模块,也即是url静态化的包
可上传pcre-7.9.tar.gz,输入如下命令安装:
#tar zxvf pcre-7.9.tar.gz
#cd pcre-7.9
#./configure
#make
#make install
安装pcre成功后,继续安装nginx
如果安装不上pcre,可用sudo apt-get install libpcre++-dev libpcre++0 安装pcre。
#cd nginx-0.7.63
#./configure
#make
#make install
4、nginx安装成功后的安装目录为/usr/local/nginx
在conf文件夹中新建proxy.conf,用于配置一些代理参数,内容如下:
#!nginx (-)
# proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; #获取真实ip
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #获取代理者的真实ip
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
最后附件我配置的nginx.conf:
#运行NGINX的用户和组
#user nobody nobody;
#启动进程数,根据cpu内核来配置;
worker_processes 1;
#配置全局错误日志
#error_log logs/error.log;
error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
#工作模式和连接数上限
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#定义日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#定义访问日志
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
#开启gzip模块
gzip on;
#定义负载均衡池,weight表示权重,值越大优先级越高,被分配到的机率越高.
upstream local_tomcat {
server 127.0.0.1:8080 weight=5;
}
#定义虚拟主机
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
#定义项目的存放路径
location / {
index index.jsp;
proxy_pass http://127.0.0.1:8080;
# root /home/hadoop/program/apache-tomcat-6.0.35/webapps/beta;
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;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
#定义状态监控
location /nginx {
#stub_status on;
access_log logs/status.log;
auth_basic "NginxStatus";
#auth_basic_user_file /usr/local/nginx/conf/htpasswd;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
#保留用户真实信息
#include proxy.conf;
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;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}