-
Couldn't load subscription status.
- Fork 1
ElasticSearch SSL
To run Elasticsearch 7 on port 443 with SSL (HTTPS) instead of the default port 9200, you need to modify the Elasticsearch configuration and set up SSL certificates. Here’s a step-by-step guide:
Before configuring SSL, you need to generate or obtain SSL certificates. You can create self-signed certificates or use certificates from a trusted Certificate Authority (CA).
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout elasticsearch.key -out elasticsearch.crtThis will create a private key (elasticsearch.key) and a certificate (elasticsearch.crt).
- elasticsearch.key: Private key.
- elasticsearch.crt: Public certificate.
Make sure these files are saved in a secure directory.
Elasticsearch uses SSL for securing communication over HTTP and transport layers. You need to update the elasticsearch.yml configuration file to enable SSL on the HTTP layer and bind it to port 443.
-
Find the
elasticsearch.ymlconfiguration file (usually located in/etc/elasticsearch/elasticsearch.ymlor/usr/share/elasticsearch/config/elasticsearch.yml). -
Add or modify the following settings in the
elasticsearch.yml:
# Enable SSL for HTTP (REST API)
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: /path/to/your/elasticsearch.p12 # Or .jks, depending on your format
xpack.security.http.ssl.keystore.password: "your-keystore-password"
xpack.security.http.ssl.truststore.path: /path/to/your/elasticsearch.p12 # Or .jks
xpack.security.http.ssl.truststore.password: "your-truststore-password"
xpack.security.http.ssl.verification_mode: full # or certificate for less strict validation
xpack.security.http.port: 443 # Change to port 443
# Disable the default port 9200
http.port: 443 # Ensure this is setIf you're using .p12 (PKCS#12) format, specify the path to your .p12 file. If you're using .jks (Java KeyStore) format, you will need to specify the path to the .jks file and provide the appropriate password.
For example, if you're using .p12:
xpack.security.http.ssl.keystore.path: /etc/elasticsearch/certs/elasticsearch.p12
xpack.security.http.ssl.keystore.password: "your-keystore-password"Port 443 is a privileged port (i.e., below 1024), so the user that Elasticsearch runs under needs the necessary permissions to bind to it.
- Linux: Ensure the Elasticsearch user can bind to port 443, which may require root or sudo privileges.
- MacOS/Windows: Similar permissions are needed.
# Open the sudoers file
sudo visudo
# Add the following line to allow the elasticsearch user to bind to port 443
elasticsearch ALL=(ALL) NOPASSWD: /bin/netstatAlternatively, you can run Elasticsearch with elevated privileges using sudo, but this is not recommended for production environments due to security concerns.
If you're running Elasticsearch behind a firewall or reverse proxy (such as Nginx or Apache), you may need to configure it to forward requests from port 443 to the actual port Elasticsearch is running on.
For example, with Nginx, you could configure it as follows:
server {
listen 443 ssl;
server_name your-domain.com;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;
location / {
proxy_pass http://localhost:9200; # Port where Elasticsearch is running
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}This way, Nginx listens on port 443, handles SSL termination, and proxies requests to Elasticsearch running on the internal port (e.g., 9200).
Once you’ve configured everything, restart Elasticsearch for the changes to take effect:
sudo systemctl restart elasticsearchTo test the SSL setup and ensure Elasticsearch is running on port 443 with SSL, you can run:
curl -X GET "https://localhost:443" -u elastic -k-
-u elastic: Replace with your Elasticsearch username (e.g.,elastic). -
-k: Ignore SSL certificate verification (useful for self-signed certificates).
If everything is set up correctly, you should receive a response from Elasticsearch over HTTPS.
- Permissions: Make sure that Elasticsearch has permission to use port 443.
- Firewall: Ensure that port 443 is open and accessible if you're using a firewall.
- Certificate Issues: If you're using self-signed certificates, you might need to disable strict certificate validation or add the certificate to your system's trusted store.
By following these steps, you should be able to run Elasticsearch 7 on port 443 with SSL.