You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
5.9 KiB

11 months ago
  1. # How to Configure HTTPS for Anything LLM AWS private deployment
  2. Instructions for manual https configuration after generating and running the aws cloudformation template (aws_build_from_source_no_credentials.json). Tested on following browsers: Firefox version 119, Chrome version 118, Edge 118.
  3. **Requirements**
  4. - Successful deployment of Amazon Linux 2023 EC2 instance with Docker container running Anything LLM
  5. - Admin priv to configure Elastic IP for EC2 instance via AWS Management Console UI
  6. - Admin priv to configure DNS services (i.e. AWS Route 53) via AWS Management Console UI
  7. - Admin priv to configure EC2 Security Group rules via AWS Management Console UI
  8. ## Step 1: Allocate and assign Elastic IP Address to your deployed EC2 instance
  9. 1. Follow AWS instructions on allocating EIP here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html#using-instance-addressing-eips-allocating
  10. 2. Follow AWS instructions on assigning EIP to EC2 instance here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html#using-instance-addressing-eips-associating
  11. ## Step 2: Configure DNS A record to resolve to the previously assigned EC2 instance via EIP
  12. These instructions assume that you already have a top-level domain configured and are using a subdomain
  13. to access AnythingLLM.
  14. 1. Follow AWS instructions on routing traffic to EC2 instance here: https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-ec2-instance.html
  15. ## Step 3: Install and enable nginx
  16. These instructions are for CLI configuration and assume you are logged in to EC2 instance as the ec2-user.
  17. 1. $sudo yum install nginx -y
  18. 2. $sudo systemctl enable nginx && sudo systemctl start nginx
  19. ## Step 4: Install certbot
  20. These instructions are for CLI configuration and assume you are logged in to EC2 instance as the ec2-user.
  21. 1. $sudo yum install -y augeas-libs
  22. 2. $sudo python3 -m venv /opt/certbot/
  23. 3. $sudo /opt/certbot/bin/pip install --upgrade pip
  24. 4. $sudo /opt/certbot/bin/pip install certbot certbot-nginx
  25. 5. $sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot
  26. ## Step 5: Configure temporary Inbound Traffic Rule for Security Group to certbot DNS verification
  27. 1. Follow AWS instructions on creating inbound rule (http port 80 0.0.0.0/0) for EC2 security group here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/working-with-security-groups.html#adding-security-group-rule
  28. ## Step 6: Comment out default http NGINX proxy configuration
  29. These instructions are for CLI configuration and assume you are logged in to EC2 instance as the ec2-user.
  30. 1. $sudo vi /etc/nginx/nginx.conf
  31. 2. In the nginx.conf file, comment out the default server block configuration for http/port 80. It should look something like the following:
  32. ```
  33. # server {
  34. # listen 80;
  35. # listen [::]:80;
  36. # server_name _;
  37. # root /usr/share/nginx/html;
  38. #
  39. # # Load configuration files for the default server block.
  40. # include /etc/nginx/default.d/*.conf;
  41. #
  42. # error_page 404 /404.html;
  43. # location = /404.html {
  44. # }
  45. #
  46. # error_page 500 502 503 504 /50x.html;
  47. # location = /50x.html {
  48. # }
  49. # }
  50. ```
  51. 3. Enter ':wq' to save the changes to the nginx default config
  52. ## Step 7: Create simple http proxy configuration for AnythingLLM
  53. These instructions are for CLI configuration and assume you are logged in to EC2 instance as the ec2-user.
  54. 1. $sudo vi /etc/nginx/conf.d/anything.conf
  55. 2. Add the following configuration ensuring that you add your FQDN:.
  56. ```
  57. server {
  58. # Enable websocket connections for agent protocol.
  59. location ~* ^/api/agent-invocation/(.*) {
  60. proxy_pass http://0.0.0.0:3001;
  61. proxy_http_version 1.1;
  62. proxy_set_header Upgrade $http_upgrade;
  63. proxy_set_header Connection "Upgrade";
  64. }
  65. listen 80;
  66. server_name [insert FQDN here];
  67. location / {
  68. # Prevent timeouts on long-running requests.
  69. proxy_connect_timeout 605;
  70. proxy_send_timeout 605;
  71. proxy_read_timeout 605;
  72. send_timeout 605;
  73. keepalive_timeout 605;
  74. # Enable readable HTTP Streaming for LLM streamed responses
  75. proxy_buffering off;
  76. proxy_cache off;
  77. # Proxy your locally running service
  78. proxy_pass http://0.0.0.0:3001;
  79. }
  80. }
  81. ```
  82. 3. Enter ':wq' to save the changes to the anything config file
  83. ## Step 8: Test nginx http proxy config and restart nginx service
  84. These instructions are for CLI configuration and assume you are logged in to EC2 instance as the ec2-user.
  85. 1. $sudo nginx -t
  86. 2. $sudo systemctl restart nginx
  87. 3. Navigate to http://FQDN in a browser and you should be proxied to the AnythingLLM web UI.
  88. ## Step 9: Generate/install cert
  89. These instructions are for CLI configuration and assume you are logged in to EC2 instance as the ec2-user.
  90. 1. $sudo certbot --nginx -d [Insert FQDN here]
  91. Example command: $sudo certbot --nginx -d anythingllm.exampleorganization.org
  92. This command will generate the appropriate certificate files, write the files to /etc/letsencrypt/live/yourFQDN, and make updates to the nginx
  93. configuration file for anythingllm located at /etc/nginx/conf.d/anything.llm
  94. 3. Enter the email address you would like to use for updates.
  95. 4. Accept the terms of service.
  96. 5. Accept or decline to receive communication from LetsEncrypt.
  97. ## Step 10: Test Cert installation
  98. 1. $sudo cat /etc/nginx/conf.d/anything.conf
  99. Your should see a completely updated configuration that includes https/443 and a redirect configuration for http/80.
  100. 2. Navigate to https://FQDN in a browser and you should be proxied to the AnythingLLM web UI.
  101. ## Step 11: (Optional) Remove temporary Inbound Traffic Rule for Security Group to certbot DNS verification
  102. 1. Follow AWS instructions on deleting inbound rule (http port 80 0.0.0.0/0) for EC2 security group here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/working-with-security-groups.html#deleting-security-group-rule