nginx配置负载均衡-分享成长

主配置文件

user nobody;worker_processes 4;

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

pid logs/nginx.pid;

events {worker_connections 1024;}

http {include mime.types;default_type application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

gzip  on;

#server {

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    #location / {
    #    root   html;
    #    index  index.html index.htm;
    #}

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

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

#server {

include /app/nginx/conf/conf.d/*.conf;}

负载均衡配置部分upstream api{server 172.17.2.25:8070;}upstream portal {server 172.17.2.25:8071;}

server {listen 443 ssl;server_name test.demo.com;ssl_certificate /app/nginx/ssl/test.demo.com/1_test.demo.com_bundle.crt;ssl_certificate_key /app/nginx/ssl/test.demo.com/2_test.demo.com.key;

    #ssl_session_cache    shared:SSL:1m;
    #ssl_session_timeout  5m;

    #ssl_ciphers  HIGH:!aNULL:!MD5;
    #ssl_prefer_server_ciphers  on;

location /api/ {proxy_pass http://127.0.0.1:8070/;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;}location /portal {proxy_pass http://portal/;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;}

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

            }

    }

编译参数configure arguments: –user=apache –group=apache –prefix=/app/nginx –with-http_stub_status_module –with-http_ssl_module –with-openssl=../openssl-1.0.2l

Leave A Comment