Home NewsX California Consumer Privacy Act (CCPA) Opt-Out Icon

California Consumer Privacy Act (CCPA) Opt-Out Icon

by info.odysseyx@gmail.com
0 comment 5 views


The advantage of using an open source solution is that you have access to the latest features (e.g., operating big data models using Python and related packages). However, the disadvantage is that you sometimes need to understand a bit about the system architecture as well as the code itself. This article will walk you through how to perform the initial port configuration in an Azure Linux web app and how to modify the defaults.

index

HTTP server and startup script

Backend Example: Python

Frontend Example: Node

HTTP server and startup script

Azure Web App (App Service) exposes ports 80/443, 443 is a commonly used encrypted port. This means that you will need to perform port forwarding when deploying to Web App, regardless of the port on which your locally developed application listens.

A typical Windows web app has IIS built in as an HTTP server, listening on port 80 by default. Regardless of the stack used (e.g. node, php, .net), IIS acts as an HTTP server. Therefore, web apps have forwarding rules pre-configured on the platform side, so users are unaware of HTTP servers and port forwarding while working.

However, the situation is different for Linux web apps. Different stacks may use different HTTP servers (e.g. node may use pm2, php may use nginx, python may use uvicorn). The same HTTP server may be used for multiple stacks (e.g. nginx may be used for php or python). Some languages ​​may even start a simple server listening on a port through an interpreter and its modules (e.g. python with http.server). Therefore, it is important to understand which HTTP server your application will run on.

In many development environments, you may remember having to type a few commands into the console to start the app before testing it. For example:

uvicorn app:test --reload
npm start

This is because various tutorials usually use it as a prerequisite to start the HTTP server (or a tool with HTTP server functionality). These tools are constantly being updated, so the command line instructions or suffix parameters vary greatly. Therefore, to manage these commands, you need the startup command functionality in your Azure Linux web app.

The following sections provide two examples and explain how to deploy the application to an Azure Linux web app and run it successfully on various stacks and HTTP servers.

Backend Example: Python

For Linux Python apps, this example uses Python’s http.server package as the HTTP server. The command to use in a local development environment is `python server.py`.

derring_0-1724229492047.png

import os
import http.server
import socketserver
from http import HTTPStatus

class Handler(http.server.SimpleHTTPRequestHandler):
    def do_GET(self):
        self.send_response(HTTPStatus.OK)
        self.end_headers()
        msg = 'scale %s' % (self.path)
        self.wfile.write(msg.encode())

port = 8000
print('Listening on port %s' % (port))
httpd = socketserver.TCPServer(('', port), Handler)
httpd.serve_forever()

derring_1-1724229519483.png

derring_2-1724229519484.png

After you’ve got your HTTP server and commands down, you can create a Linux Python web app and deploy your code directly.

derring_3-1724229580444.png

Remember the port mappings I mentioned earlier? The Python environment provided by Azure Web Apps forwards port 8000 to exposed port 443 by default, so for this code, you don’t need to set up any additional port forwarding rules after deployment. You just need to modify the start command.

derring_4-1724229627848.png

Don’t forget to restart the app before doing any real testing.

derring_5-1724229646470.png

derring_ji_6-1724229646470.png

For example, if your application needs to change the default listening port to 7999, you would need to override the default port forwarding rule by adding `WEBSITES_PORT=7999` in your app settings in addition to modifying the port name in your code.

derring_7-1724229767325.png

derring_8-1724229767326.png

To verify that your application is actually listening on port 7999, go to the Kudu site and run the following command:

netstat -tulpn | grep LISTEN

derring_9-1724229790298.png

derring_10-1724229821918.png
derring_ji_11-1724229821918.png

Frontend Example: Node

For Linux Node apps, this example uses pm2 as the HTTP server. The command to use in your local development environment is `npm start`.

npx create-react-app reactfailreact-app
cd  reactfailreact-app
npm start

derring_12-1724229898388.png

derring_13-1724229898389.png

derring_14-1724229898390.png

Azure Linux Node Web Apps have pm2, a lightweight process manager with an HTTP server that is suitable for experimentation. You can create a Linux Node Web App, compile your code, and deploy it.

derring_15-1724229976438.png

The Node environment provided by Azure Web Apps forwards port 3000 to exposed port 443 by default, so for this code, you don’t need to set up any additional port forwarding rules after deployment. You just need to modify the start command.

Compile the project by running the following command. After running, a build subfolder will be created.

npm run build

derring_16-1724230044753.png

Create or modify `build/.deployment` with the following contents:

[config]
SCM_DO_BUILD_DURING_DEPLOYMENT=false

derring_17-1724230092793.png

Publish your project by specifying a build subfolder during the publishing process.

derring_18-1724230116680.png

derring_19-1724230116681.png

derring_20-1724230116682.png

Go back again AppAfter going to configuration, specify the start command as follows:

pm2 serve /home/site/wwwroot --no-daemon --spa 

deringji_24-1724230216195.png

After restarting the web app, you can visit webpages using your browser.

derring_25-1724230233523.png

For example, if your application needs to change the default listening port to 2999, you would need to override the default port forwarding rule by adding `WEBSITES_PORT=2999` in the app settings in addition to specifying the listening port in the start command.

pm2 serve /home/site/wwwroot --no-daemon --spa --port 2999

You can also go to the Kudu site and run the following command:

netstat -tulpn | grep LISTEN

derring_26-1724230337515.png





Source link

You may also like

Leave a Comment

Our Company

Welcome to OdysseyX, your one-stop destination for the latest news and opportunities across various domains.

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

Laest News

@2024 – All Right Reserved. Designed and Developed by OdysseyX