Spring Boot Deployment with NGINX Proxy

In this article we will learn how to expose Spring Boot web application with the help of NGINX reverse proxy.

Install NGINX

Let’s begin with installation of NGINX, for this tutorial we will be using Ubuntu linux. We will use NGINX official distribution and to get the relevant binaries for our Ubuntu system, we will first check the Codename of our Ubuntu installation. Run following command to get the Codename of Ubuntu Instalation.

 lsb_release -a

The output of this command will be something like following.

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.6 LTS
Release:	16.04
Codename:	xenial

In this case the code name is xenial.

Now we will add the link to NGINX official repository to sources.list of ubuntu. Open /etc/apt/sources.list using your favourite text editor, for this tutorial I will be using nano.

sudo nano /etc/apt/sources.list

Add following line to the end of sources.list file, pelase remember to replace the xenial with Codename of your Ubuntu release.

deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx

Save and exit the editor, for nano press Ctrl + O to save the file and Ctrl + X to exit the editor.

Run following command to download signing key for NGINX repository.

sudo wget http://nginx.org/keys/nginx_signing.key

Add the repository signing key (downloaded in previous step) to apt.

sudo apt-key add nginx_signing.key

If the command was successful it will print OK on screen.

OK

Now update the apt package manager index using the apt update command.

sudo apt update

Finally we will install the NGINX using apt package manager as following.

sudo apt install nginx

Run following command to check if NGINX was successfully installed.

nginx -v

Above command will print the version string of installed NGINX server.

nginx version: nginx/1.19.2

Run following command to enable NGINX service.

sudo systemctl enable nginx

Output of this command will be something like.

Synchronizing state of nginx.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable nginx
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_CTYPE = "UTF-8",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_CTYPE = "UTF-8",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").

NGINX has been installed successfully on your system, you can use following commands to start or stop NGINX service.

sudo service nginx start
sudo service nginx stop

Run following command to check the current status of NGINX servcie.

sudo service nginx status

This will print current status of NGINX service as following.

● nginx.service - nginx - high performance web server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-09-24 19:49:40 UTC; 5s ago
     Docs: http://nginx.org/en/docs/
  Process: 6753 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 6755 (nginx)
    Tasks: 2
   Memory: 1.3M
      CPU: 7ms
   CGroup: /system.slice/nginx.service
           ├─6755 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.con
           └─6756 nginx: worker process                   

Sep 24 19:49:40 ams-dev systemd[1]: Starting nginx - high performance web server...
Sep 24 19:49:40 ams-dev systemd[1]: Started nginx - high performance web server.

To proceed with following steps you will have to setup your spring boot application as service. If you are not familiar with this process, pelase following read this article.

NGINX Configuration

In context of this article we will assume Spring Boot application is up and running on HTTP port 8080.

We will start with creating a configuration file for our new virtual server. Remember to replace the name of the conf file "testserver" accordingly.

sudo nano /etc/nginx/conf.d/testserver.conf

Copy following configuration to testserver.conf.

server {
        listen 80;
        listen [::]:80;

        server_name testserver.com;

        location / {
             proxy_pass http://localhost:8080/;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header X-Forwarded-Proto $scheme;
             proxy_set_header X-Forwarded-Port $server_port;
        }
}

Shoket Mahmood Ahmed

65 thoughts on “Spring Boot Deployment with NGINX Proxy

  1. These were some very valid and well placed thoughts. Adding to your last part, I want to continue that part. I do think that she did make a new body for herself with no powers because at the end the watch had no power and when the MC reunites with Cro at the end, it never stated that the watch began to tick again so she may have come back as a human with no powers and thereby no power in the watch anymore Agata Braden Docilu

  2. I plan to take CPP, 65 or later. Currently retired, and live comfortably on a company pension. Using tax table strategy to draw down the registered investments. Hate paying tax! Have a few health issues, so shall see how that plays out and will adjust accordingly. Lacee Vale Edita

  3. I think the problem for me is the energistically benchmark focused growth strategies via superior supply chains. Compellingly reintermediate mission-critical potentialities whereas cross functional scenarios. Phosfluorescently re-engineer distributed processes without standardized supply chains. Quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Denise Byrom Goff

  4. I precisely needed to appreciate you once again. I am not sure the things that I might have gone through in the absence of the entire opinions documented by you directly on such a industry. It had been a very frightening difficulty in my circumstances, however , looking at the skilled manner you managed that made me to jump over fulfillment. I am happier for this help and even hope you find out what a great job you are doing instructing other individuals through the use of your site. I know that you have never encountered all of us. Mellisent Dwight Lam

  5. I simply wanted to type a simple comment so as to appreciate you for the great solutions you are sharing here. My rather long internet lookup has at the end been honored with high-quality knowledge to share with my good friends. I would mention that most of us readers actually are definitely blessed to live in a good site with many special people with very beneficial basics. I feel rather privileged to have come across your entire webpage and look forward to some more awesome minutes reading here. Thank you once again for all the details. Annabella Norbie Hurst

  6. hi!,I really like your writing so much! proportion we communicate extra approximately your article on AOL? I require a specialist on this area to unravel my problem. May be that is you! Taking a look forward to look you. Sybyl Herbie Wenn

  7. First mover advantage stealth crowdsource angel investor backing accelerator seed round startup client freemium burn rate supply chain infrastructure success. Infographic success growth hacking traction startup pitch twitter hackathon launch party niche market strategy burn rate infrastructure. Jody Garald Adrea

  8. Sed facilisis nibh eu lobortis consequat. Mauris et velit molestie, auctor eros suscipit, tempor vela neque, hendrerit vel pulvinar ut, ornare nec sapien. Suspendisse bibendum id molestie felis eget. Lorem ipsum dolor sit amet, est te posidonium omittantur, eu eum noster alienum graecis vix. Joelynn Torin Aguste

  9. I have been browsing online more than 2 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my view, if all webmasters and bloggers made good content as you did, the internet will be much more useful than ever before.| Bette Far Bertle

  10. I as well as my guys have been going through the good items found on your website and so instantly came up with a horrible feeling I had not thanked the website owner for those strategies. These young boys are actually certainly happy to learn all of them and have sincerely been having fun with these things. Appreciate your getting well kind as well as for making a choice on these kinds of perfect resources most people are really desperate to understand about. Our sincere regret for not expressing gratitude to you sooner. Meridel Giffie Woodman

  11. Do you have a spam problem on this site; I also am a blogger, and I was curious about your situation; many of us have created some nice procedures and we are looking to swap methods with others, be sure to shoot me an e-mail if interested. Deerdre Durand Bianca

  12. One other issue is when you are in a predicament where you do not possess a cosigner then you may genuinely wish to try to wear out all of your financial aid options. You will discover many awards and other free college funding that will present you with money to help with college expenses. Thank you for the post. Hedwiga Gery Natalee

  13. Thank you for the sensible critique. Me and my cousin were just preparing to do some research on this. We grabbed a book from our local library but I think I learned better from this post. I am very glad to see such magnificent info being shared freely out there.. Kaylee Herschel Sheryle

  14. I was excited to uncover this page. I need to to thank you for your time just for this wonderful read!! I definitely appreciated every part of it and I have you saved as a favorite to see new information on your web site. Allene Hartwell Lowry

  15. I think this is among the most significant info for me. And i am glad reading your article. But want to remark on some general things, The web site style is wonderful, the articles is really excellent : D. Good job, cheers Nettle Aldric Peadar

  16. Having read this I believed it was rather informative. I appreciate you spending some time and effort to put this informative article together. I once again find myself spending way too much time both reading and leaving comments. But so what, it was still worth it! Amandie Ax Ursi

  17. There are certainly a lot of details like that to take into consideration. That is a great point to bring up. I offer the thoughts above as general inspiration but clearly there are questions like the one you bring up where the most important thing will be working in honest good faith. I don?t know if best practices have emerged around things like that, but I am sure that your job is clearly identified as a fair game. Both boys and girls feel the impact of just a moment?s pleasure, for the rest of their lives. Dinah Mickey Oakleil

  18. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You obviously know what youre talking about, why waste your intelligence on just posting videos to your weblog when you could be giving us something enlightening to read? Stormie Yuma Prince

  19. hi!,I like your writing so much! percentage we keep up a correspondence more approximately your post on AOL? I require an expert in this area to resolve my problem. Maybe that is you! Having a look forward to see you. Philippine Cullie Amaryl

  20. I used to be recommended this website by my cousin. I am now not
    sure whether or not this put up is written by means of him as no one else recognize
    such exact approximately my trouble. You are wonderful! Thanks!

Leave a Reply

Back to top