Configuring VestaCP for Standalone Web Applications

Hello everyone,

Ümit Aksoylu
6 min readJan 2, 2022

--

As you know; oldschool developers mostly uses PHP for backend. Then we can say; server control panels are very required things especially when using PHP backend. They provide us too many things like MySQL (Or another DB) configuration, PHP engine support, Nginx & Apache and such many things.

So, we can talk about a couple of server CP’s; VestaCP, CPanel, Plesk Panel ..

They mostly have usage area for PHP backend. But of course we should be able to use them with a mix of another backend technologies.

Okay, now we need to define “Standalone” apps. As we say, those apps are “Standing alone”. You know, when you create a new “container” with a server CP; panel automatically working directory for you. And you just need to upload your PHP files into the that directory. After that transfer, your new web app is able to run.

It happens because in backend of the story; CP handles many configuration for us. Thanks to that, we can link multiple domains with different web apps on our server. We able to do that because CP always handling nginx, apache and database configurations for us.

Those are not standalone apps. Remember that, a standalone will work with itself, with invading a unique port. According to the above information; running a classic NodeJS server app (Express or not) or a Python server app (Flask, Django or not) is a standalone app.

Because they invade a UNIX port each a process. But in our PHP + CP example, all containers are linked to one port. And if we can reach or web app by visiting <domain.com>, we need to know nginx routes 80 port to our PHP Apache or without Nginx, PHP & Apache directly invades 80 port of server.

The first scenario is understandable for ideal server management and this is actually how Cp’s handling our server. But second one is terrible.

So, we will continue with the first scenario. How can we implement our “Standalone” web app (Developed with any technology other than php) on our Nginx configuration ?

Step 1 : Prepare your DNS configuration for routing

We should call our app like “domain.com:8180" but we will assume that we need directly visit “webapp-domain.com” domain for calling our app.,

So, first step is handling DNS configuration on the domain provider. We need to route our domain to our server’s IP address.

As you can see above, i route my “alphagan.aksoylu.space” domain to my server’s IP on my domain provider.

Step 2: Avoid messing with Cp

My first mistake was resisting to CP’s nginx configuration. Escepically i say this for Vesta (But i think this is always reliable for all CP’s)

When i write a conf file, CP always overrides that. That makes me mad many times but finally i accept that we can’t fix problem by resisting CP.

The second step is generating a web container on our CP (In that example, using VestaCp). This is actually what we usually do for creating a new PHP app on our vestaCP-ruled server.

We can do this on vestaCP by clicking that button.

And then configure the new container like classic PHP app but with using our new domain :

But of course, we don’t doing this for a new PHP app.

Now we can realize that so far process is similar as creating new PHP app. But after that stage, things will goes different.

Step 3: Play the game with CP’s rules.

Now we can manipulate the VestaCP’s nginx configuration for our will. First of all we will establish a ssh connection to our server. We need to know, VestaCP always stack nginx configurations under /home/<username>/conf/web directory.

And here is nginx configurations for my web apps that created by VestaCp (Yeah i know, i am running too many app for one server :D )

And we need to know, the conf file named as “alphagan.aksoylu.space.httpd.conf” and “alphagan.aksoylu.space.nginx.conf” files are just now created by previous step that we do on CP.

We don’t have any job with file ends with “httpd.conf”. So, don’t tamper that.

In the other hand, let’s take a look at file ends with “nginx.con” :

Well, this is looks like little a bit confused but don’t worry. Most of this code is automatically created by CP for benefits of PHP server. Of course we do not need them for our standalone web app.

Continuing with cleaning them :

Okay, we did our configuration. But what we did different from cleaning unnecessary lines ?

Let me explain;

1 ) “Listen” value should 80 if you use “http://” protocol. If you need to serve your app as “https://”, you should change it to “443”.

2) “Proxy_pass” value in “Location/” section should define our web apps correct endpoint. I placed here http://46.45.163.57:8106 because firstly my app uses http protocol. Secondly my server ip address is 46.45.163.57 and i want to run my app in 8106 port.

You should fill that line with your apps requirements.

Okay, now we can restart nginx with new configuration by running “service nginx restart” command on bash:

If you can see the message above, you did true thing (At least, you not broke nginx conf syntax :D )

Okay, now lets try our web app by visiting our domain that we supplied to nginx :

Step 4: Approaching to final, What goes wrong ?

Nothing, i just want to remember that; do not forget to run your web app when messing with nginx configuration.

Now we need run our standalone web app in 8106 port (Port that which we defined in nginx conf )

This is my server.py file (My standalone web app using flask, so i configured my http server settings for python & flask syntax)

and after that, i will start my app by running “python3 server.py” command on bash :

Oh, it looks like running. Lets take a look in browser :

It’s alive ! Thanks for reading :)

Have a good day

Ümit Aksoylu

--

--