把nginx 安装到 /usr/local 下(默认安装)
下载nginx
wget http://nginx.org/download/nginx-0.8.53.tar.gz
tar xzvf nginx-0.8.53.tar.gz
cd nginx-0.8.53
./configure --with-http_stub_status_module --with-http_ssl_module #启动server状态页和https模块
如出现错误说缺少PCRE library 这个是HTTP Rewrite 模块,也即是url静态化的包
可上传pcre-7.9.tar.gz,输入如下命令安装:
1.
#tar zxvf pcre-
7.9
.tar.gz
2.
#cd pcre-
7.9
3.
#./configure
4.
#make
5.
#make install
make
make install
配置nginx
在 /usr/local/nginx 下创建 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_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;
打开 /usr/local/nginx/conf/nginx.conf
标红为更改过的内容
#运行nginx所在的用户名和用户组
.
#user www www;
worker_processes 2;
#全局错误日志及PID文件
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
#Specifies the value
for
maximum file descriptors that can be opened by
this
process.
.
worker_rlimit_nofile
65535
;
#工作模式及连接数上限
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
include /usr/local/nginx/conf/proxy.conf;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name en.pipgame.com;
index index.html index.htm index.jsp;
root /data1/home/pipstat/tomcat6029_8181/webapps/web_sg_en;
location ~ .*.jsp$ #所有jsp的页面均交由tomcat处理
{
index index.jsp;
proxy_pass http://localhost:8181; #转向tomcat处理
}
location ~ .*.action$ #所有jsp的页面均交由tomcat处理
{
index index.jsp;
proxy_pass http://localhost:8181; #转向tomcat处理
}
location ~ .*$ #所有jsp的页面均交由tomcat处理
{
index index.jsp;
proxy_pass http://localhost:8181; #转向tomcat处理
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ #设定访问静态文件直接读取不经过tomcat
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
location / {
index index.html index.htm index.jsp;
}
#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;
}
}
}
启动nginx
/usr/local/nginx/sbin/nginx
停止nginx
/usr/local/nginx/sbin/nginx -s stop