NGINX、JDK部署配置

  1. jdk部署配置
    tar zxvf jdk1.7.0_79 mv jdk1.7.0_79 /usr/local/jdk1.7.0_79
  2. 编辑文件写入一下配置
    vim /etc/profile.d/java.sh加入如下配置
    JAVA_HOME=/usr/local/jdk1.7.0_79
    JAVA_BIN=/usr/local/jdk1.7.0_79/bin
    JRE_HOME=/usr/local/jdk1.7.0_79/jre
    PATH=$PATH:/usr/local/jdk1.7.0_79/bin:/usr/local/jdk1.7.0_79/jre/bin
    CLASSPATH=/usr/local/jdk1.7.0_79/jre/lib:/usr/local/jdk1.7.0_79/lib:/usr/local/jdk1.7.0_79/jre/lib/charsets.jar
    source /etc/profile.d/java.sh //及时生效
    如果以上配置成功,则下面的命令可以看到java的版本: java -version
    =======================
  3. 安装nginx所需依赖
    yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
    yum install –y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
  4. 下载解压
    cd /usr/local/src/
    wget http://nginx.org/download/nginx1.6.2.tar.gz
    tar zxvf nginx-1.6.2.tar.gz cd nginx-1.6.2
  5. 安装所需路径以及模块
    ./configure
    --prefix=/usr/local/nginx
    --with-http_realip_module
    --with-http_ssl_module
    --with-http_sub_module
    --with-http_stub_status_module
    --with-http_gzip_static_module
    --with-pcre \
  6. 编译安装
    make
    make install
    执行echo $?进行检查
    /usr/local/nginx/sbin/nginx 启动nginx
    /usr/local/nginx/sbin/nginx -s reload 重启nginx
  7. 编写nginx启动脚本
    vim /etc/init.d/nginx //加入如下内容

!/bin/bash

chkconfig: - 30 21

description: http service.

Source Function Library

. /etc/init.d/functions

Nginx Settings

NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=03
prog="Nginx"

start() {
echo -n "Startingprog: "
mkdir -p /dev/shm/nginx_temp
daemon NGINX_SBIN -cNGINX_CONF
RETVAL=? echo returnRETVAL
}

stop() {
echo -n "Stoppingprog: "
killproc -p NGINX_PIDNGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=? echo returnRETVAL
}

reload(){
echo -n "Reloadingprog: "
killproc -p NGINX_PIDNGINX_SBIN -HUP
RETVAL=? echo returnRETVAL
}

restart(){
stop
start
}

configtest(){
NGINX_SBIN -cNGINX_CONF -t
return 0
}

case "1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo"Usage: 0 {start|stop|reload|restart|configtest}" RETVAL=1 esac exitRETVAL
保存后,执行
chmod a+x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
----nginx配置文件示例----

  1. 头部公共配置
    user nobody nobody;
    worker_processes 2;
    error_log /usr/local/nginx/logs/nginx_error.log crit;
    pid /usr/local/nginx/logs/nginx.pid;
    worker_rlimit_nofile 51200;

events
{
use epoll;
worker_connections 6000;
}

http
{
server_tokens off
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip 'remote_addrhttp_x_forwarded_for [time_local]' 'host "request_uri"status'
'"http_referer" "http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 300m;
client_body_buffer_size 16k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml;


  1. 负载均衡
    nginx 的upstream使用sticky,如下
    upstream cluster_test {
    sticky;
    server 192.168.100.209:80;
    server 192.168.100.225:80;
    }
  2. 反向代理配置
    server {
    listen 7001;
    server_name 192.168.0.3;
    location /{
    proxy_pass http://172.1.1.10:7001;
    proxy_set_header Host host:server_port;
    proxy_set_header X-Real-IP remote_addr; proxy_set_header X-Forwarded-Forproxy_add_x_forwarded_for;
    }
    }
  3. 日志切割
    add_header X-Frame-Options SAMEORIGIN;
    log_format main 'remote_addrremote_user [time_local] "request" '
    'statusbody_bytes_sent "http_referer" ' 'http_user_agent http_x_forwarded_forrequest_time upstream_response_timeupstream_addr $upstream_status';
  4. 配置静态文件
    location ~ .*.(gif|jpg|jpeg|png){ expires 24h; root /web/resource/UploadFiles/SystemFile/; access_log /usr/local/nginx/logs/images.log; proxy_store on; proxy_store_access user:rw group:rw all:rw; proxy_temp_path /web/resource/UploadFiles/SystemFile/; proxy_redirect off; proxy_set_header host 127.0.0.1; client_max_body_size 10m; client_body_buffer_size 1280k; proxy_connect_timeout 900; proxy_send_timeout 900; proxy_read_timeout 900; proxy_buffer_size 40k; proxy_buffers 40 320k; proxy_busy_buffers_size 640k; proxy_temp_file_write_size 640k; if ( !-erequest_filename)
    {
    proxy_pass http://192.168.1.88:10054;
    }
    }
  5. 端口转发-将9000端口转发映射至 8080
    server {
    listen 8080;

    listen somename:8080;

     server_name  localhost;
     location / {
     proxy_pass http://localhost:9000 ;
     proxy_set_header Host $host:8080;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Via "nginx";
     }
    
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容