您的位置:首页 > 运维架构 > Nginx

centos(其他linux系统类似)中安装nginx

2011-12-22 17:41 751 查看
最近一台服务器上需要部署2个tomcat,每个tomcat上的工程都要80端口访问,于是乎想到用nginx做代理转发。

特将安装过程mark一下:

系统:centos 5.2

准备的包:

nginx-0.7.67.tar.gz

openssl-1.0.0a.tar.gz

zlib-1.2.5.tar.gz

pcre-8.10.zip(linux下zip文件是可以解压缩的~~~~ unzip)

将4个包放到一个目录下,假设为/home/project

解压4个包~~~

为了方便,将解压后的nginx-0.7.67目录改为nginx(mv命令就行了~~~),openssl-1.0.0a目录改为openssl,zlib-1.2.5目录改为zlib,pcre-8.10改为pcre

然后进入nginx目录

./configure
--sbin-path=/usr/local/nginx/nginx
--conf-path=/usr/local/nginx/nginx.conf
--pid-path=/usr/local/nginx/nginx.pid
--with-http_ssl_module
--with-pcre=../pcre
--with-zlib=../zlib

然后再make

make install

哦了~~ 在/usr/local/nginx启动./nginx就行了~~~~ 当然你还要根据你的需求配置nginx.conf。网上n多~~~~

user  nobody;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  crit;

pid        logs/nginx.pid;

worker_rlimit_nofile 65535;

events {
use epoll;
worker_connections  65535;
}

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  100;

gzip  on;
gzip_min_length  1k;
gzip_buffers     4 8k;
gzip_http_version  1.1;
gzip_types       text/plain application/x-javascript text/css text/javascript application/xml;
gzip_comp_level 2;
gzip_vary on;

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;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

server {
listen       80;
server_name  xx.com;

charset utf-8;

#access_log  logs/host.access.log  main;
access_log off;

location ~* ^.+.(jpg|jpeg|gif|png|ico|css|html|swf|xml|htm)$ {
root /usr/raycloud/project/crm_client/ROOT;
expires           30d;
access_log off;
}

location ~* ^.+.(js|css)$ {
root /usr/raycloud/project/crm_client/ROOT;
expires           1d;
access_log off;
}

#
location / {
proxy_pass http://127.0.0.1:8088; 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;

}

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}

}

server {
listen       80;
server_name  xx.com;

charset utf-8;

#access_log  logs/host.access.log  main;
access_log off;

location / {
proxy_pass http://127.0.0.1:8089; 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;

}

#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;
}

}

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: