Nginx简单说明

Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器

JEPaaS集成Nginx配置

  • 下载Nginx管理工具,进行安装。下载地址:http://nginx.org

  • 解压到指定盘符,运行nginx.exe(即nginx -c conf\nginx.conf),默认使用80端口

  • 修改配置文件,一般都在conf/nginx.conf

server {
    listen 80; #配置端口号 
    server_name test.jepaas.com;#配置证书的域名 
    rewrite ^ https://$http_host$request_uri? permanent; #配置http强制 跳转
}

server { 
    listen 443 ssl; #配置证书端口号 
    server_name test.jepaas.com; #配置证书的域名
    ssl_certificate /data/application/openresty/nginx/cert/4044925_test.jepaas.com.pem; #证书文件的路径(客户需要改成自己的路径) 
    ssl_certificate_key /data/application/openresty/nginx/cert/4044925_test.jepaas.com.key; #秘钥文件的路径 
    ssl_session_cache shared:SSL:1m; 
    ssl_session_timeout 5m; 
    ssl_ciphers HIGH:!aNULL:!MD5; 
    ssl_prefer_server_ciphers on; 
    charset utf-8; 
    #access_log /var/log/nginx/host.access.log main; 
    access_log /data/application/openresty/nginx/logs/test.jepaas.log main; #日志文件路径 

    location /socket.io/ {
        proxy_redirect off; #proxy_buffers 8 32k; #proxy_buffer_size 64k; 
        proxy_read_timeout 300s;
        proxy_send_timeout 300s; 
        proxy_http_version 1.1; 
        proxy_set_header Upgrade $http_upgrade; 
        proxy_set_header Connection "upgrade"; # proxy_set_header Connection $connection_upgrade; 
        proxy_request_buffering off; 
        proxy_buffering off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host; #proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:7001/socket.io/; #代理socket, localhos t为socket所在服务器ip 
    }
    location /jesocket {
        proxy_redirect off; #proxy_buffers 8 32k; #proxy_buffer_size 64k; 
        proxy_pass http://localhost:7000/jesocket; #代理socket, localhost 为jesocket所在服务器ip 
        proxy_read_timeout 300s; 
        proxy_send_timeout 300s; 
        proxy_http_version 1.1; 
        proxy_set_header Upgrade $http_upgrade; 
        proxy_set_header Connection "upgrade"; # proxy_set_header Connection $connection_upgrade; 
        proxy_request_buffering off; 
        proxy_buffering off; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header Host $host; #proxy_set_header X-NginX-Proxy true; 
    }
    location ^~ /instant {
        proxy_pass http://localhost:8088; ##代理instant, localhost为instan t所在服务器ip 
        proxy_redirect off; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host; 
        client_max_body_size 50m; 
        client_body_buffer_size 256k; 
        proxy_connect_timeout 1; 
        proxy_send_timeout 30; 
        proxy_read_timeout 60;
        proxy_buffer_size 256k;
        proxy_buffers 4 256k; 
        proxy_busy_buffers_size 256k; 
        proxy_temp_file_write_size 256k; 
        proxy_next_upstream error timeout invalid_header http_500 http_5 03 http_404; 
        proxy_max_temp_file_size 128m;
    }
    location / { 
        proxy_pass http://localhost:8080;#jepaas主服务,localhost为jepaas 主服务所在服务器ip 
        proxy_redirect off; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header X-Real-IP $remote_addr; 
        proxy_set_header Host $http_host; 
        client_max_body_size 100m; 
        client_body_buffer_size 256k; 
        proxy_connect_timeout 1; 
        proxy_send_timeout 30; 
        proxy_read_timeout 60; 
        proxy_buffer_size 256k; 
        proxy_buffers 4 256k; 
        proxy_busy_buffers_size 256k; 
        proxy_temp_file_write_size 256k; 
        proxy_next_upstream error timeout invalid_header http_500 http_50 3 http_404; 
        proxy_max_temp_file_size 128m; 
    }
}

注意事项

  • 注意监听的端口、域名地址
  • 代理地址还需要注意指定websocket配置地址,如果是本地部署的websocket,并且与平台启动服务在同一台服务器上,则代理地址就配置当前平台访问地址的IP或域名,反之则推送服务启动地址是哪一个,Nginx的配置文件中websocket地址就指定哪一个
最后编辑: 呼丽华  文档更新时间: 2024-08-21 10:58   作者:呼丽华