0

I have a spring boot application deployed on AWS and using the spring boot endpoints through the Nginx server with reverse proxy. When I send Hindi text in the request it automatically gets converted to some random string to the backend. I checked the server log and found the random string of Hindi text.

Server log

checked the browser network console for request headers of the content-type header and everything is okay

What should be the correct Nginx configuration needed to get Hindi text as is to the backend? Please suggest something My current Nginx configuration is as follows:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    
     client_max_body_size 10M;

        server {
        client_max_body_size 10M;
        }

}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

Browser console

  • 1
    I highly doubt if it has anything to do with nginx. More than likely, it's an issue of not having correct default character encoding for spring boot JVM. Did you try bypassing nginx and try posting this request directly to spring boot application on **same** AWS server? Use curl or wget from same host ssh console to verify it. Please post back your findings in order for others to help you sort out this issue. – Avnish Jul 15 '20 at 10:28
  • I tried running the same code on the local system without Nginx on windows machine. I directly called the localhost endpoint. I found it was running without having any issue – chirag soni Jul 15 '20 at 10:57
  • not the local machine, try it on the **_same_** aws server. This is common scenario where aws server configuration and/or jvm itself result into different behaviors across environments. Please try it over a ssh session on the same server where you are seeing the issue. – Avnish Jul 15 '20 at 11:04
  • Yes. @Avnish you were correct. I tried the curl on AWS command and still, I have the same issue it's not related to Nginx. ubuntu@ip-172-31-36-225:~$ curl -X PUT -H "Content-Type: application/json" -d '{"id":13,"serviceId":162,"detailedDescription":"खंडवा रोड पर कृषि फार्म "}' localhost:8091/api/0.1/property-detail/13 RESPONSE => {"id":13,"serviceId":162,"detailedDescription":"????? ??? ?? ???? ????? "} – chirag soni Jul 15 '20 at 11:15
  • Can you help me how can I fix this – chirag soni Jul 15 '20 at 11:16
  • Depending on how you are launching spring boot app (systemd, initd etc) on server, you'll have to set JVM default character encoding to UTF-8 accordingly. Take a look at solutions presented in [How to set UTF-8 character encoding in Spring boot?](https://stackoverflow.com/questions/39163590/how-to-set-utf-8-character-encoding-in-spring-boot). I am positive this will sort out the issue you are having. – Avnish Jul 15 '20 at 11:23
  • I added `server.servlet.encoding.charset=UTF-8` to the application.properties and also tried adding the JVM arguments but it was not working. So I debug this at every level from controller, service, and repository everything was okay. After doing everything I just added the charset to the connection string of the DB. `spring.datasource.url=jdbc:mysql://localhost:3306/smart_shop_service?allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=utf8 ` and it started working. Thanks for your all suggestions. – chirag soni Jul 16 '20 at 07:37

0 Answers0