PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label azure-web-app-service. Show all posts
Showing posts with label azure-web-app-service. Show all posts

Tuesday, October 18, 2022

[FIXED] How to pull image from existing azure container registry?

 October 18, 2022     azure, azure-container-registry, azure-web-app-service, docker     No comments   

Issue

Created a docker image. Deployed the app as web service; create a registry and push the image to azure container and the app is running fine online. I tried to login but cant. Username or password incorrect. On top of that my laptop crashed and I did not save a copy.

Can someone help me on how to pull the image from acr with the source code and download to my local machine. I found some tutorial online but was a bit vague.

Please help


Solution

  1. Login to your Azure account
az login
  1. Login to Azure Container Registry
az acr login --name $REGISTRY
  1. Pull your Image
docker pull ${REGISTRY}.azurecr.io/${IMAGE}:${TAG}

Optionnal: List your images

az acr repository list -n $REGISTRY --output table


Answered By - Reda E.
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, September 28, 2022

[FIXED] How to publish Grunt-assembled web site to the root of Azure Web App using Kudu?

 September 28, 2022     azure-web-app-service, continuous-deployment, gruntjs, kudu     No comments   

Issue

I have a web site assembled (is it the right term?) by Grunt. It has the following structure:

/
  src/ (input)
    doc/
    images/
    js/
    scss/
    Web.config
  external/
  node_modules/
  dist/ (output)
    css/
    fonts/
    images/
    js/
  gruntfile.js
  package.json

To publish it to an Azure Web App using Continuous Deployment and Kudu I added the following files:

.deployment
deploy.cmd

I can upload the web site to /src and deploy it to /dist like this:

Directory of D:\home\site\wwwroot

06/30/2015  01:50 AM    <DIR>          .
06/30/2015  01:50 AM    <DIR>          ..
06/30/2015  02:21 AM                30 .deployment
06/30/2015  02:21 AM             3,679 deploy.cmd
06/30/2015  12:44 AM    <DIR>          dist
06/30/2015  12:40 AM    <DIR>          external
06/30/2015  02:21 AM             5,697 gruntfile.js
06/30/2015  12:43 AM    <DIR>          node_modules
06/30/2015  02:21 AM             1,173 package.json
06/30/2015  12:40 AM    <DIR>          src

But when I specify the root as the destination I'm getting an error:

Source and destination directories cannot be sub-directories of each other

What is the right approach here?


Solution

Edit: Changing answer based on discussion

Try using Virtual Directories: https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/

All sites have site\wwwroot point to the / virtual directory by default. If you want \dist to be your root then change the virtual directory entry to have site\wwwroot\dist as the physical path and / as the virtual directory.

enter image description here

You can configure you web.config to specify any script to be your startup script with the following config:

  <system.webServer>
    <handlers>
      <add name="iisnode" path="/src/index.js" verb="*" modules="iisnode" />
    </handlers>
  </system.webServer>



Answered By - Zain Rizvi
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why would azure be restarting website when i do a deployment slot swap?

 September 28, 2022     azure, azure-web-app-service, continuous-deployment, continuous-integration     No comments   

Issue

I've a .net 4.5 website running on Azure Websites. I've a staging deployment set up. I warm up both sites and then i run the swap process (both from azure portal and from Azure powershell). No matter what I try the swapping process restarts my websites (both) and they take about 3 minutes to boot up.

I was under the impression the deployment swapping was supposed to keep the websites "warm" and have no down time? My websites are unusuable for about 3 minutes!

As far as I can tell both production and staging slots have the same application settings etc.

Any advice or pointers would be greatly appreciated.


Solution

Jeff is right. When there are sticky app settings or connection strings defined for the slot then the website's worker process will be restarted during the swap. The sequence of actions that happen in that case is this:

  1. Apply the sticky settings from production slot to the site's worker process that is currently in staging slot. That causes the restart of worker process;
  2. Warm up the site's worker process in the staging slot by making http requests to its root URL on every VM instances where site should be running;
  3. Swap the worker processes between slots. Now the warmed up worker process is in production slot and is accepting production traffic;
  4. Apply the sticky settings from staging slot to the worker process that is currently in staging slot. At this point this is the "used to be in production" worker process. This config change causes restart of that worker process, but at that point it does not take any production traffic.


Answered By - RuslanY
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I access deployment history in Azure Web Apps?

 September 28, 2022     azure, azure-web-app-service, continuous-deployment, continuous-integration, git     No comments   

Issue

I set up multiple deployment slots for a web app. We have continuous deployment configured on the staging slot, so each Git commit on a specific branch triggers a deployment to my staging slot. Once verified, we swap the staging and production slots. Is there a way to view (and redeploy if desired) the deployment history for a slot? I don't want to be limited to simply reverting the swap, but be able to select a specific deployment.

The Continuous deployment setting for the staging slot shows only two deployments, even though there have been many more. Is there a way to access the full deployment history?

Deployment History for Staging Slot


Solution

When dealing with slots, the behavior is a bit complex (and you might argue confusing!). The trickiness comes from the fact that the deployment history moves with the content of the site when you perform swaps.

I'll illustrate by example:

  • You start with a production slot (i.e. the main app), and a staging slot. No deployments have happened yet.
  • Deployment #1 happens to the Staging slot
  • You swap to production
  • At this point, you will see no history in the Staging slot because the history was swapped to the Production slot.
  • Now you deploy #2 to the Staging slot, and you swap Production.
  • The history on the Staging slot now has #1, as it got swapped back in there.
  • Deploy #3 and swap
  • The history on the Staging slot now has #2.
  • Next time you swap again, the Staging slot history has #1 and #3

So you get the idea: each slot will contain alternating history items. #1, #3, #5, etc in one slot, and #2, #4, #6, etc in the other.

To make this a bit more subtle, while both slot contain history items, the Portal only shows history for slots that are enabled for deployment. So while your Production slot contains history items, the Portal does not show them (this does need to be addressed).

As a workaround, you can go to https://{yoursite}.scm.azurewebsites.net/ and click on Deployments to get the deployment list in the Production slot. This is a REST API, and not a fancy UI.

Hopefully this helps clarify this admittedly confusing behavior :)



Answered By - David Ebbo
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to handle Azure web app versioning?

 September 28, 2022     azure, azure-web-app-service, continuous-deployment, deployment     No comments   

Issue

I am about to develop a new website (SaaS) project and want to use Azure as the platform. I want every clients data to be isolated from each other which i chose to achieve by using elastic database engine.

Each client must have a specific endpoint like bla.siteName.com, bla2.siteName.com, bla3.siteName.com this is easily achieved by subsomains and usage of custom domains.

And finally website itself should be hosted on azure web app but here is where i hit a wall.

I want to be able to move each client at a time to the newer version of the web application.

So if My web app is runing version 1.0, and i add a new feature in version 1.1, i want to be able to move client and clients db to version 1.1 without them noticing it.

So far my thought is to publish new web app version 1.1 and move subdomain name of that specific client to version 1.1 web app. But this will end up in downtime, because switch of subdomains take time.

Am i missing something or am i just about to overengineer something that is very simple?

Or should i just focus on single website serve all approach, and just upgrade all clients databases at once?


Solution

You may want to try Azure Deployment Slots. It has many uses, including the one you describe. You can use Azure Traffic Routing to route a subset of your users to one of your deployment slots.



Answered By - Randy Minder
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, September 27, 2022

[FIXED] How to handle Outage images in Azure WebApp

 September 27, 2022     asp.net, azure, azure-web-app-service, continuous-deployment     No comments   

Issue

We are hosting our website in Azure. During the deployment(TFS) we will do the below Steps as the part of the deployment pipeline.

  1. Stop the WebApp
  2. Deploy Web App Service
  3. Start the WebApp

After the 1st step, if anyone tries to access our website, then by default Azure will return the below page

enter image description here

We really don't want our users to show this page during the outage. We are planning to show our own outage image/page in such case.

Is there is any way to achieve this?

Since Azure Web Apps in a Paas model, I'm wondering how to do this?

Any inputs Appreciated!


Solution

It seems that it does not suppport custom error page at this time. There is feedback on Enabling users to create custom error pages for 403 and 503 service unavailable messages.

I think you could up vote to promote the realization of this feature.



Answered By - Joey Cai
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, September 26, 2022

[FIXED] How to remove Github workflow, Azure Webapp CD / CI with Github Repo

 September 26, 2022     azure-devops, azure-web-app-service, continuous-deployment, github     No comments   

Issue

can someone help point a direction how to setup Azure Webapp with CD / CI please? I have a github repo, which i want to connect to a url, when the master branch is updated.

I tried following tutorial, and try setup https://dev.azure.com/ account, to which I'm not sure how, but the url : http://bss-olr.azurewebsites.net/ seems to have been connected, although i cant see how to take down the github workflow. (ie: I want to take it down, and reuse the same URL again)

Can someone help point the right direction? Azure is quite confusing with many outdated documentations.. Thanks in advance.


Solution

You should check out this updated Azure tutorial: Continuous deployment to Azure App Service. It shows you how to enable continuous deployment for your web app via the Azure portal.enter image description here



Answered By - Grace MacJones - MSFT
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, September 6, 2022

[FIXED] How to prevent an existing file being uploaded via Visual Studio Publish

 September 06, 2022     asp.net-core, azure-web-app-service, c#, visual-studio, web-deployment     No comments   

Issue

Maybe it's a common or silly question but I didn't find any appropriate solution.

I have a JSON file located at my www-root folder, I don't want to upload this file every time I publish my website using Visual Studio.

How can I do that?

I'm using the latest build of Visual Studio 19 and ASP.NET CORE 3.1


Solution

Look at the following links. Should do the trick.

  1. Link1
  2. Link2


Answered By - rohit
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, August 19, 2022

[FIXED] How to override web.config values in custom section in Azure Web App?

 August 19, 2022     azure, azure-web-app-service, environment-variables, web-config     No comments   

Issue

It is possible in Azure Web App to override web.config AppSettings section easily. E.g. if I have the following web.config:

<appSettings>   
    <add key="AllowedCORSOrigin" value="http://localhost:26674"/>
</appSettings>

I can override it in the app settings UI in the portal like that:

enter image description here

I have also a custom section in the web.config:

<AdWordsApi>
    <add key="OAuth2RefreshToken" value="TOKEN" />
</AdWordsApi>

Is it possible to override it somehow as well? I have tried AdWordsApi.OAuth2RefreshToken and AdWordsApi:OAuth2RefreshToken, but that does not work that easily.

P.S. It's interesting to know if it's possible with other custom sections like e.g if I want another authentication mode on the server.

<system.web>
    <authentication mode="None" />
</system.web>

Solution

Short answer is that it is not possible.

The mechanism you describes only works with App Settings and Connection Strings. High level, the way it works is:

  • Your Azure App Settings become environment variables
  • At runtime, a special module sets those dynamically in the .NET config system. Note that the physical web.config is never modified.

But it would be hard to make such mechanism work on arbitrary config sections, as those could not be dynamically affected without modifying the physical file.



Answered By - David Ebbo
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, July 25, 2022

[FIXED] How to host json-server in azure

 July 25, 2022     angular, azure-web-app-service, javascript, json, json-server     No comments   

Issue

I am new in the software field, please have patience with my question and mistakes of technical terms:

Premises:- I have developed an front-end application using Angular4. The baseURL define in angular application is 'http://localhost:3000/'. My application uses restangular api to interact with json-server (I created a folder named json-server and it has db.json and public folder ). It is working perfectly fine when i start the json-server using command: json-server json-server --watch db.json

My application is finalized and thus I created a production build. Thereafter I moved all my files from dist folder to public folder of json-server. When i start the json-server, my application works fine.

Actual problem:- Now I wanted to host in azure. I simply copied all file/folder (db.json and public folder) from json-server folder as it is and put them in azure cloud. When azure hosting is done and I open the url in browser I got an error- "you don't have permission to view".

To rectify above error I deleted all files from azure and then I copied all files of dist folder and put them in azure cloud. Using this I could able to see the application in the browser but no images. At image there is an error- Response with status: 0 for URL: null

When I start json-server locally, everything works fine but of course when same web page open from other machines I got the same error- Response with status: 0 for URL: null

Is there any way to run json-server in azure so that all machines/mobile when accessing the url, can see proper web page without any error.


Solution

Step to step to run json-server on Azure Web App:

  1. Open your browser and go to App Service Editor (https://<your-app-name>.scm.azurewebsites.net/dev/wwwroot/)

  2. Run the command in the Console (Ctrl+Shift+C)

    npm install json-server --save-dev
    
  3. Put all file/folder (db.json and public folder) into wwwroot folder

  4. Create a server.js with the following content

    const jsonServer = require('json-server')
    const server = jsonServer.create()
    const router = jsonServer.router('db.json')
    const middlewares = jsonServer.defaults()
    
    server.use(middlewares)
    server.use(router)
    server.listen(process.env.PORT, () => {
      console.log('JSON Server is running')
    })
    
  5. Click Run (Ctrl+F5), this will generate web.config file automatically and open your website in the browser.

    enter image description here



Answered By - Aaron Chen
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, July 16, 2022

[FIXED] How to Publish .Net solution containing multiple projects through Visual Studio to Azure

 July 16, 2022     azure, azure-web-app-service, visual-studio, visual-studio-2017, web-deployment     No comments   

Issue

I'm having a .Net Solution with 2 Projects. I've created a webapp in azure for deployment. So, i downloaded publishsetting file from Azure webapp.

Is there anyway to publish the entire solution[multiple projects] to that webapp using downloaded publishsettings file.

I see that only one project can be published to azure. Please suggest


Solution

Hosting on the same Azure Web App with different slots

First, you'll need to define your second slot. This can be done in the portal by navigating to your Web App's management blade, then clicking the Deployment Slots menu option. Once a slot is defined, you can click on it under the Deployment Slots menu, and you'll be taken to a totally separate Overview tab for the slot. Note that on this page, you can download a totally separate Publish Profile for the slot.

With two web applications in the same Visual Studio solution, you can right click on each, choose "Publish", then use a primary or slot publish profile to determine where each web application will be published.

Multiple custom domain names for different web applications in one Azure Web App

Use the same steps as above. After publishing both of your sites (using two slots - the primary and the new slot you define), browse to the Custom Domains tab in each slot. Here, you can set up each custom domain so that Azure will route traffic to the appropriate slot accordingly.



Answered By - Rob Reagan
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, July 13, 2022

[FIXED] How do I deploy to Azure App Service with PowerShell (az module)?

 July 13, 2022     azure, azure-web-app-service, powershell, web-deployment     No comments   

Issue

I want to deploy app services from Powershell. I would like to use only publish profile (no password for azure account).

I tried FTP service, but sometimes files are blocked by running users. I think I have to stop app service.

There is powershell command like:

Publish-AzWebApp

However first I need login with:

Connect-AzAccount

and pass credentials what I want to avoid.

There is any way to call Publish-AzWebApp based on only publish profile (no login by account)?

Connect-AzAccount has other options to login (token or certificate). Unfortunately I don't know how to generate it.

BTW There was a topic about it: How do I deploy to Azure App Service with PowerShell? But it is old and now module "az" is recommended.


Solution

There is any way to call Publish-AzWebApp based on only publish profile (no login by account)?

No, you can't. If you want to use the Publish-AzWebApp , you always need to login with Connect-AzAccount, whatever the parameters you use, examples here.

If you want to use powershell to deploy the web app based on only publish profile, the workaround is to use Kudu API via powershell.

$username = "`$webappname"
$password = "xxxxxxx"
# Note that the $username here should look like `SomeUserName`, and **not** `SomeSite\SomeUserName`
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
$userAgent = "powershell/1.0"

$apiUrl = "https://joywebapp.scm.azurewebsites.net/api/zipdeploy"
$filePath = "C:\Users\joyw\Desktop\testdep.zip"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST -InFile $filePath -ContentType "multipart/form-data"


Answered By - Joy Wang
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, June 25, 2022

[FIXED] How reverse proxy with SSL/TSL and plain traffic works?

 June 25, 2022     azure, azure-web-app-service, docker, reverse-proxy, ssl     No comments   

Issue

I have a containerized Docker ASP.NET Core application created with

mcr.microsoft.com/dotnet/core/runtime:3.1.3-alpine 

When launched the only reference to the port is this ENV variable from the base image

ASPNETCORE_URLS http://+:80

I deployed the app to Azure, setuped the registry and created a new Web Application.
I setup the TLS/SSL settings for working with https only.

Everythings works.

Question:

I want to know how this is possible since I don't config the certificate on my container, I suppose the Kudu service (the reverse proxy) rebind the 443 port to the 80 of the container. Is this true ? The plain http traffic between Kudu and the container on port 80 can cause a possible security hole ?

If I deploy a container with NGINX as a reverse-proxy for ASP.NET Core I must configure the TSL/SSL into NGINX ? On ASP.NET Core ? None at all ?

I want to understand how Kudu, NGINX, and the reverse proxy in general works with and without SSL/TSL


Solution

With a Reverse Proxy the client never connects to the HTTP server in your application, in your case Kestrel. The connections you get are requests coming from the Reverse Proxy, and you send your responses back to the Reverse Proxy. Most HTTP stuff is copied from the incoming client request and passed along to your application, but the Reverse Proxy can terminate the SSL tunnel, offload the Authentation, and perform other request transformations.



Answered By - David Browne - Microsoft
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, February 2, 2022

[FIXED] Protocol being switched during redirects

 February 02, 2022     azure, azure-web-app-service, cakephp, cakephp-3.0, php     No comments   

Issue

In my CakePHP 3.10 application, the redirects are changing the protocols and breaking the app. This is being deployed to an App Service (PHP 7.4) in Azure.

I'm not seeing this on another LAMP stack (RHEL, Apache 2.4, PHP 7.3, https configured) on premise.

Example, logging out of the application.

public function logout()
{
    $this->getRequest()->getSession()->write('isAdmin',false);
    $this->Flash->success(__('You are now logged out.'));
    return $this->redirect($this->Auth->logout());
}

During inspection of the traffic (via Edge's > Inspect > Network), here's what I see (notice Response Header Location change from https to http):

General

Request URL: https://my.domain.com/users/logout
Request Method: GET
Status Code: 302 Found
Remote Address: my.ip.here:443
Referrer Policy: strict-origin-when-cross-origin

Response Headers

Cache-Control: no-store, no-cache, must-revalidate
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Date: Sun, 19 Dec 2021 13:08:05 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Location: http://my.domain.com/
Pragma: no-cache
Server: Apache
Set-Cookie: CAKEPHP=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; HttpOnly
Set-Cookie: CAKEPHP=c2be7c7d45c9418b06356bd95796ff8f; path=/; HttpOnly
X-Powered-By: PHP/7.4.24

Request Headers

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Cookie: csrfToken=09206701259fb54445122132512cf0e8f00cf2ac2f2cf42a34a49cd221b9e797c36d919696daad8d2fc77a0373e417e5e59a89a0cacc9c408ebeede1fc0b4446; CAKEPHP=c6ebd1412956de948b4857c4a0791f04
DNT: 1
Host: my.domain.com
Referer: https://my.domain.com/
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Microsoft Edge";v="96"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62

Solution

Like many load balancers, the Azure ones also like to terminate SSL, so that the requests that are reaching PHP will be unencrypted, making the env('HTTPS') lookup fail that CakePHP applications use by default to build the full base URL.

/*
 * Set the full base URL.
 * This URL is used as the base of all absolute links.
 *
 * If you define fullBaseUrl in your config file you can remove this.
 */
if (!Configure::read('App.fullBaseUrl')) {
    $s = null;
    if (env('HTTPS')) {
        $s = 's';
    }

    $httpHost = env('HTTP_HOST');
    if (isset($httpHost)) {
        Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost);
    }
    unset($httpHost, $s);
}

https://github.com/cakephp/app/blob/3.10.1/config/bootstrap.php#L131-L148

The linked Azure docs suggest checking the HTTP_X_FORWARDED_PROTO header instead, which is being populated by the load balancer, but you need to take into account that depending on the environment that the application runs in, this header could also have been set by the client, so I wouldn't generally recommend using it.

I would instead suggest to hardcode the protocol, or better yet, set the complete full base URL manually (at least in the past HTTP_HOST has been a problem too, as some servers accepted custom values sent from the client), eg:

Configure::write('App.fullBaseUrl', 'https://' . $httpHost);

or set App.fullBaseUrl in your config/app.php (or config/app_local.php).



Answered By - ndm
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing