Question

i would like the site you currently have at http://ipserver:8080/project/ to be served as www.example.com. I use glassfish server. Thanks

i would like the site you currently have at http://ipserver:8080/project/ to be served as www.example.com. I use glassfish server. Thanks

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Good morning, yesterday configure from digital ocean and nginx as they left me in the last comment, but until now I do not work the url with the www. Am I missing something else?

I send you my settings.

In nginx in the example.com file

server {
         Listen 80;
         Listen [::]: 80;

         Server_name example.com www.example.com;

         Location / {
         Proxy_pass http: // ipServer: 8080 / Example /;
         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;
         }
}

** In digital ocean **

*A @ --> ipServer

CNAME www --> @*

Yes, i use digital ocean. Try it. Thanks

It worked perfect. The only detail left is:

example.com works www.example.com not work

I need some configuration to accept the www?

Thanks again!

Great!! Nginx was installed already. Now, you could tell me how would the /etc/nginx/sites-enabled/default file for the case of using 2 or more projects in different urls?

Example

159.203.100 … :8080/ Project1 to www.project1.com 159.203.100 … :8080/ Project2 to www.project2.com

Thank you very much!!!

You need a Reverse Proxy. As you use Nginx (assuming from tag), it’s very simple.

Open your default server block (or any you want to use):

  1. sudo nano /etc/nginx/sites-available/default

Find `location / block and delete any content from it. Make sure it looks like this:

...
location / {
proxy_pass http://localhost:8080/project/;
        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;
}
...

Save file, exit editor and restart nginx:

  1. sudo systemctl nginx restart

You should get desired results. To learn more about it, you can refer to this tutorial which covers both Nginx and Apache. I personally recommend Nginx as it better suit reverse proxy needs.

There are two ways to accomplish this, either reconfigure Glassfish to listen on port 80 or install an nginx reverse proxy in front of it.

##Option 1

To have Glassfish listen on port 80:

  1. Connect to the administration interface (by default on port :4848)

  2. In the left menu go to Configurations

  3. Then select the appropriate configuration you need to change eg server-config

  4. Then go to Network Config

  5. Then go to Network Listeners

  6. Select the appropriate listener, probably http-listener-1

  7. Change the Port value to 80

  8. Save and reboot your glassfish server/instance/cluster according to your needs

##Option #2

To configure an nginx reverse proxy, first install nginx. On Ubuntu this can be done with sudo apt-get install nginx. Once installed, open the file /etc/nginx/sites-enabled/default and modify it so it reads:

server {

        listen 80 default_server;
        listen [::]:80 default_server;

        server_name _;

        location / {
        proxy_pass http://localhost:8080/project/;
        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;
    }

}

Then restart nginx for the changes to take effect:

sudo service nginx restart