Pages

Bài đăng phổ biến

Thursday, September 1, 2022

Resolved : Nginx reverse proxy for AWS IoT MQTT over TLS

Problem : you can not configure http to reverse proxy for aws iot mqtt ,  java client would return these errors : 
software.amazon.awssdk.crt.mqtt.MqttException: socket is closed.

at software.amazon.awssdk.crt.mqtt.MqttClientConnection.onConnectionComplete(MqttClientConnection.java:140)


Resolved : 


You must use nginx module: ngx_stream_proxy_module ( like network load balancer) this is a template to resolve : 


        Stream{

        map $ssl_preread_server_name $domain {
        stg-iot.yourdomain  stg-iot;
        iot.yourdomain prod-iot;
        }

        upstream stg-iot {
                server IoT-xxxxxx..ap-your_region-1.amazonaws.com:443;
        }

       upstream prod-iot {
                server IoT-xxxxxx..ap-your_region-1.amazonaws.com:443;
        }
  map $ssl_server_name $targetCert {
    stg-iot.yourdomain /etc/nginx/ssl/star_yourdomain.crt;
    iot.yourdomain /etc/nginx/ssl/star_yourdomain.crt;
  }

    map $ssl_server_name $targetCertKey {
    stg-iot.yourdomain /etc/nginx/ssl/star_yourdomain.key;
    iot.yourdomain /etc/nginx/ssl/star_yourdomain.key;
  }

        server {
                listen 443;
    ssl_certificate     $targetCert;
    ssl_certificate_key $targetCertKey;
                proxy_pass $domain;
                ssl_preread on;
        }

             } 

===============================================================

Feel free to use them without concern! 

Nginx reverse proxy for AWS IoT MQTT over TLS 

Nguyen Si Nhan

Saturday, June 27, 2015

Logrotate with nginx

/path_to_accesslog/access.log {
    missingok
    notifempty
    size 100000k
    daily
    create 0644 www root
    postrotate
[ ! -f /etc/nginx/logs/nginx.pid ] || kill -USR1 `cat /etc/nginx/logs/nginx.pid`
    endscript
}

Explain:

missingok :  do not output error if logfile is missing
notifempty : do not rotate if logfile is empty
size             : Log file is rotated if it is  bigger than 100000KB
daily            : daily rotation
create 0644 www root : create new logfile with permission 644 where owner is www and group is root user.
postrotate
[ ! -f /etc/nginx/logs/nginx.pid ] || kill -USR1 `cat /etc/nginx/logs/nginx.pid`
    endscript

=> tells nginx reload the log files .

Finish!!!

Nguyen Si Nhan

Sunday, November 10, 2013

Install/Setup windows from Usb


1. Download and extract WinSetupFromUSB and run it.
2. Mark checkbox corresponding to Windows 2000/XP/2003 Setup and locate installation source or CD that contains I386 or AMD64 folders.
3. Now click on Go button to start copying installation source to USB stick and finalizing all sort of things.



Once its Done! you can restart your PC and boot from USB stick. You need to follow 3-Steps installation, viz:
    1. Text mode setup
    2. GUI mode setup
    3. Start Windows for first time