California Consumer Privacy Act (CCPA) Opt-Out Icon by info.odysseyx@gmail.com August 21, 2024 written by info.odysseyx@gmail.com August 21, 2024 0 comment 5 views 5 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`. 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() After you’ve got your HTTP server and commands down, you can create a Linux Python web app and deploy your code directly. 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. Don’t forget to restart the app before doing any real testing. 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. 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 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 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. 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 Create or modify `build/.deployment` with the following contents: [config] SCM_DO_BUILD_DURING_DEPLOYMENT=false Publish your project by specifying a build subfolder during the publishing process. Go back again AppAfter going to configuration, specify the start command as follows: pm2 serve /home/site/wwwroot --no-daemon --spa After restarting the web app, you can visit webpages using your browser. 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 Source link Share 0 FacebookTwitterPinterestEmail info.odysseyx@gmail.com previous post Postdoctoral Fellow, Pentlands Science Park, UK next post Just a moment… You may also like Built-in Oracle DB – using JKS keystore to support certification validation September 9, 2024 How to Stand Out as a Microsoft Student Ambassador: Perks, Process, and More… September 9, 2024 Optimizing a Terabyte-Scale Azure SQL Database September 7, 2024 Installation/Validation of extension-based hybrid worker September 7, 2024 New Surface Pro & Surface Laptop September 7, 2024 What's new in Microsoft Teams (free) | Aug 2024 September 6, 2024 Leave a Comment Cancel Reply Save my name, email, and website in this browser for the next time I comment.