下载压缩包
wget http://nginx.org/download/nginx-1.6.3.tar.gz
解压
tar -zxvf nginx-1.6.3.tar.gz
安装配置(这里默认)
./configure
这里一般会有几个依赖错误:
./configure: error: the HTTP gzip module requires the zlib library
yum install zlib-devel
./configure: error: C compiler cc is not found
yum -y install gcc
./configure: error: the HTTP rewrite module requires the PCRE library
yum install pcre-devel
再次执行
./configure
出现如下就ok了
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using builtin md5 code
+ sha1 library is not found
+ using system zlib library
可以看到OpenSSL和sha1未找到,这里可以不用管,但如果想用其功能可以安装对应的依赖
yum install openssl openssl-devel
yum install perl-Digest-SHA1.x86_64
./configure --with-http_stub_status_module --with-http_ssl_module
编译 安装
make && make install
cd /usr/local/nginx/
vim /etc/profile
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
source /etc/profile
测试下
nginx -v
配置文件 默认路径(/usr/local/nginx/conf/)
#Nginx所用用户和组,window下不指定
#user niumd niumd;
#工作的子进程数量(通常等于CPU数量或者2倍于CPU)
worker_processes 2;
#错误日志存放路径
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
#指定pid存放文件
pid logs/nginx.pid;
events {
#使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。
#use epoll;
#允许最大连接数
worker_connections 2048;
}
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 off;
access_log logs/access.log;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 75 20;
proxy_next_upstream off;
#include gzip.conf;
upstream localhost {
#根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能,需要通过缓存进行共享解决。
#同一机器在多网情况下,路由切换,ip可能不同
ip_hash;
server localhost:8090;
}
server {
listen 8080;
server_name 127.0.0.1; #这里设置域名或者请求ip
location / {
proxy_connect_timeout 30;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://localhost;
}
#静态文件访问
location ~ ^/(upload|static)/ {
root /data/www;
expires 2d;
}
}
}
检查配置文件是否正确
nginx -t
启动
nginx
重启
nginx -s reload
关闭可以直接kill掉进程
ps -ef | grep nginx
kill -9 nginx