1. 安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
2. 安装PCRE
PCRE库支持正则表达式。如果我们在配置文件nginx.conf中使用了正则表达式,那么在编译Nginx时就必须把PCRE库编译进Nginx,因为Nginx的HTTP模块需要靠它来解析正则表达式。
- wget下载安装包
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
- 解压并进入目录
tar -zxvf pcre-8.35.tar.gz
cd pcre-8.35
- 编译安装
./configure
make && make install
-- 查看版本
pcre-config --version
3. 安装nginx
- 下载安装包
wget http://nginx.org/download/nginx-1.6.2.tar.gz
- 解压并进入目录
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
- 编译安装
./configure 命令的 --prefix 用于指定安装路径,--with用于指定依赖 --with-依赖包名称=依赖包目录
如果不使用 --prefix 指定路径,则安装时可执行文件默认放在 /usr/local/bin ,库文件默认放在 /usr/local/lib ,配置文件默认放在 /usr/local/etc 。其它的资源文件放在 /usr/local/share
./configure --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/tools/pcre-8.35
make && make install
4. 配置nginx
进入/usr/local/nginx/conf,将 nginx.conf 替换为以下内容
#user nobody;
worker_processes 2;
worker_rlimit_nofile 20000;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 20000;
}
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;
#keepalive_timeout 0;
keepalive_timeout 600;
client_max_body_size 50m;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /unified {
alias /usr/local/nginx/html/unified/ ;
index index.html index.htm;
try_files $uri $uri/ /index.html last;
}
location /centralf {
alias /usr/local/nginx/html/centralf/ ;
index index.html index.htm;
try_files $uri $uri/ /index.html last;
}
location /personalf {
alias /usr/local/nginx/html/personalf/ ;
index index.html index.htm;
try_files $uri $uri/ /index.html last;
}
location /ecf {
alias /usr/local/nginx/html/ecf/ ;
index index.html index.htm;
try_files $uri $uri/ /index.html last;
}
location /platform {
proxy_pass http://127.0.0.1:6010/api/;
}
location /personal {
proxy_pass http://127.0.0.1:6050/api/;
}
location /central {
proxy_read_timeout 300s;
proxy_pass http://127.0.0.1:6070/api/;
}
location /ec {
proxy_pass http://127.0.0.1:6060/api;
proxy_read_timeout 300;
}
#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;
#}
}
# HTTPS server
# server {
# listen 443 ssl;
# server_name localhost;
# ssl on;
# ssl_certificate /usr/local/nginx/cert/2920010_sc.schfuture.com.pem;
# ssl_certificate_key /usr/local/nginx/cert/2920010_sc.schfuture.com.key;
# ssl_session_timeout 5m;
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_prefer_server_ciphers on;
#
#
# # admin
# location /platform {
# proxy_pass http://39.108.161.153:6010/api/;
# }
#
# }
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# server_name somename alias another.alias;
#
# location / {
# root html;
# index index.html index.htm;
# }
#
# location /mng {
#
# alias /usr/local/nginx/html/manage/ ;
# index index.html index.htm;
# try_files $uri $uri/ /index.html last;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
5. 检查配置文件正确性
/usr/local/nginx/sbin/nginx -t
6. 启动nginx
/usr/local/nginx/sbin/nginx