====== Performexa - HTTPS Support ====== "Requirement" and "Design & Implementation" remains same as Learnexa (Referrence: https://wiki.exphosted.com/doku.php/https_support) ====== HTTPS Migration - app Checklist ====== 1> Change the environments/.rb file and add/modify the strings below APP_URL = "https://app-url.com" API_URL = "https://app-url.com" AUTHENTICATION_URL = "https://app-url.com" SSL_ENABLED = true HTTP_ONLY_HEADER = "HTTP_X_HTTP_ONLY" 2> Update chat.yml server: https://app-url.com:5280 bosh: https://app-url.com:5280/http-bind websocket: wss://app-url.com:5280/websocket 3> Update ejabberd.yml (Path:- /opt/ejabberd/conf/ejabberd.yml) listen: - port: 5280 module: ejabberd_http request_handlers: "/websocket": ejabberd_http_ws # "/pub/archive": mod_http_fileserver web_admin: true http_poll: false http_bind: true tls: true certfile: "/opt/ejabberd-15.04/conf/server.pem" ## register: true captcha: false s2s_use_starttls: required s2s_certfile: "/opt/ejabberd-15.04/conf/server.pem" 4> Get the certificate files needed and add for rails app and ejabberd. (Note: ejabberd expects .pem files) a) For rails app - Configure your server to serve the certificate. b) For ejabberd - place the certificate in /opt/ejabberd/conf/server.pem and restart. 5> Modify Nginx configuration to work with SSL worker_processes 1; events { worker_connections 1024; } http { passenger_root /home/expdev01/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/passenger-5.0.20; passenger_ruby /home/expdev01/.rbenv/versions/2.2.3/bin/ruby; include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name performance.exphosted.com; rewrite ^/?(.*) https://$host/$1 redirect; } server { listen 443 ssl; ssl on; ssl_certificate /opt/nginx/ssl/server.crt; ssl_certificate_key /opt/nginx/ssl/server.key; server_name performance.exphosted.com; passenger_user expdev01; passenger_enabled on; passenger_app_env staging; root /deploy/performance/current/public; } } ==== Developer Notes ==== 1) Generating private SSL Key and Certificate openssl req -x509 -new -nodes -keyout server.key -days 365 -out server.crt -config /etc/pki/tls/openssl.cnf > Country Name (2 letter code) [XX]:IN > State or Province Name (full name) []: > Locality Name (eg, city) [Default City]: > Organization Name (eg, company) [Default Company Ltd]: > Organizational Unit Name (eg, section) []: > Common Name (eg, your name or your server's hostname) []: > Email Address []: 2) Starting THIN server in SSL mode thin start -p 3000 --ssl --ssl-key-file --ssl-cert-file 3) Generating PEM file for ejabberd and placing it to be served. Take backup of server.pem, present inside /opt/ejabberd/conf, as server.pem.bak Then run this code to replace the .pem file with the generated key and certificate > sudo cat > /opt/ejabberd/conf/server.pem ====== Reverting back to HTTP ====== 1> Change the environments/.rb file and add/modify the strings below APP_URL = "http://app-url.com" API_URL = "http://app-url.com" AUTHENTICATION_URL = "http://app-url.com" SSL_ENABLED = false 2> Update chat.yml server: http://app-url.com:5280 bosh: http://app-url.com:5280/http-bind websocket: ws://app-url.com:5280/websocket 3> Revert changes in /opt/ejabberd/conf/ejabberd.yml (## represents code is commented) listen: - port: 5280 module: ejabberd_http request_handlers: "/websocket": ejabberd_http_ws # "/pub/archive": mod_http_fileserver web_admin: true http_poll: false http_bind: true ## tls: true ## certfile: "/opt/ejabberd-15.04/conf/server.pem" ## register: true captcha: false ## s2s_use_starttls: required ## s2s_certfile: "/opt/ejabberd-15.04/conf/server.pem" 4> Revert back the /opt/ejabberd/conf/server.pem file with the backup taken earlier (server.pem.bak) 5> Revert back Nginx configuration to work without SSL worker_processes 1; events { worker_connections 1024; } http { passenger_root /home/expdev01/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/passenger-5.0.20; passenger_ruby /home/expdev01/.rbenv/versions/2.2.3/bin/ruby; include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name performance.exphosted.com; passenger_user expdev01; passenger_enabled on; passenger_app_env staging; root /deploy/performance/current/public; } }