1.下载yum源
2.安装openresty服务
yum -y install openresty openresty-resty
3.添加nginx服务

vim /usr/lib/systemd/system/openresty.service
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/local/openresty/nginx/sbin/nginx -c /etc/nginx/nginx.conf

4.添加服务
systemctl daemon-reload

cp /usr/local/openresty/nginx/conf /etc/nginx/ -R

mkdir /etc/nginx/vhosts

5.添加开机服务

systemctl enable openresty

6.配置nginx代理

vim /etc/nginx/nginx.conf

user  www  webgrp;

worker_processes  2;
#worker_cpu_affinity  0001 0010 0100 1000;
worker_rlimit_nofile    102400;
pid /usr/local/openresty/nginx/logs/nginx.pid;
#pid  /var/run/nginx.pid;
#google_perftools_profiles /data/www/cache/tmp/tcmalloc;

error_log  /var/log/nginx_error.log  info;

events {
    worker_connections 102400;
    use epoll;
}


http {
    include  /etc/nginx/mime.types;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 1024m;

    default_type  application/octet-stream;

    proxy_hide_header X-Powered-By; 
    proxy_hide_header Server;


    sendfile        on;

    keepalive_timeout  65;
    tcp_nodelay on;

    fastcgi_connect_timeout 1800;
    fastcgi_send_timeout 1800;
    fastcgi_read_timeout 1800;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;

    add_header X-Cache-CFC "$upstream_cache_status - $upstream_response_time 221";
 #   fastcgi_temp_path /data/www/cache/ngx_fcgi_tmp;
 #   fastcgi_cache_path /data/www/cache/ngx_fcgi_cache levels=1:2 keys_zone=ngx_fcgi_cache:1024m inactive=15m max_size=16g;
    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

  #  proxy_temp_path /data/www/cache/ngx_proxy_tmp;
  #  proxy_cache_path /data/www/cache/ngx_proxy_cache levels=1:2 keys_zone=ngx_proxy_cache:1024m inactive=6h max_size=10g;
 


    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
        '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent"  $http_x_forwarded_for $request_body '
         '"$upstream_cache_status" $upstream_status'
        ' upstream_response_time $upstream_response_time request_time $request_time';

    log_format  access-s  '$remote_addr - $remote_user [$time_local] "$request" '
        '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent"  $http_x_forwarded_for '
         '"$upstream_cache_status" $upstream_status'
        ' upstream_response_time $upstream_response_time request_time $request_time';

    log_format  access-url  'curl  -s "http://tyapi.qun7.com$request_uri" -d  "$request_body" ';

 

    open_log_file_cache  max=1000 inactive=60s;


    limit_req_zone  $binary_remote_addr  zone=qps1:1m   rate=1r/s;
    limit_req_zone  $binary_remote_addr  zone=qps2:1m   rate=2r/s;
    limit_req_zone  $binary_remote_addr  zone=qps3:1m   rate=3r/s;

        proxy_hide_header X-Powered-By;
        proxy_hide_header Server;
        access_log /var/log/access.log access;
        server_tokens off;


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

    map $http_x_forwarded_for  $clientRealIp {
        ""      $remote_addr;
        ~^(?P<firstAddr>[0-9\.]+),?.*$  $firstAddr;
     }   

#    upstream common{
#        server 127.0.0.1:9000;
#        server 127.0.0.1:9001;
#        server 127.0.0.1:9002;
 #   }

    fastcgi_next_upstream error timeout invalid_header http_503  http_500;


   # server
   # {
   #     listen 80 default;
   #     server_name _; 
   #     return 444;
   # }
    include vhosts/*.conf;

}

7. 添加大数据服务器需要代理的服务

vim /etc/nginx/vmhost/all.conf

#yarn

server {
    listen 120.79.20.59:8088;
    server_name 120.79.20.59 dbos-bigdata-test002;

    index index.html index.htm index.php;

        #include /usr/local/nginx/conf/allow_ip.conf;
        # deny all;
    location / {
        proxy_pass http://10.66.93.134:8088;
    }


    access_log  /data/logs/access/test.com.access.log  access;
    error_log   /data/logs/error/test.com.error.log warn;
}

# namenode

server {
        listen 120.79.20.59:9870 ;
        server_name 120.79.20.59 dbos-bigdata-test002;

        index index.html index.htm index.php;

     #   include /usr/local/nginx/conf/allow_ip.conf;
     #   deny all;
        location / {
            proxy_pass http://10.66.93.134:9870;
        }
}              

# yarn history

server {
        listen 120.79.20.59:19888 ;
        server_name 120.79.20.59 dbos-bigdata-test002;

        index index.html index.htm index.php;

     #   include /usr/local/nginx/conf/allow_ip.conf;
     #   deny all;
        location / {
            proxy_pass http://10.66.93.134:19888;
        }
}

# oozie 

server {
    listen 120.79.20.59:11000;
    server_name 120.79.20.59 dbos-bigdata-test002;
    index index.html index.htm index.php;
    location / {
        proxy_pass http://10.66.93.134:11000;
    }
    access_log  /data/logs/access/test.com.access.log  access;
    error_log   /data/logs/error/test.com.error.log warn;
}

8.重新openresty加入配置

systemctl reload  openresty

9.重启openresty服务

systemctl restart openresty

10.访问各个服务测试

阿里云大数据服务器安装代理nginx端口转发_nginx