Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Beta 8 Hosting error: HTTP Error 502.3 - Bad Gateway #466

Closed
mdmoura opened this issue Nov 5, 2015 · 18 comments
Closed

Beta 8 Hosting error: HTTP Error 502.3 - Bad Gateway #466

mdmoura opened this issue Nov 5, 2015 · 18 comments
Assignees

Comments

@mdmoura
Copy link

mdmoura commented Nov 5, 2015

Hello,

I created a new MVC Beta 8 project using simply the default template.

When I publish the project and host it on a server using IIS 8.5 I get the error:

HTTP Error 502.3 - Bad Gateway
There was a connection error while trying to route the request.

The CGI application did not return a valid set of HTTP errors.
A server acting as a proxy or gateway was unable to process the request due to an error in a parent gateway.
  1. I am using Windows Server 2012 R2 with IIS 8.5;
  2. I have the application running on a No Managed code application pool
  3. I have HttpPlataformHandler 1.2 installed.

What might be wrong?

Thank You,
Miguel

@Eilon
Copy link
Member

Eilon commented Nov 5, 2015

@Tratcher can you take a look?

@Tratcher
Copy link
Member

Tratcher commented Nov 6, 2015

@mdmoura Have you been following #364?

@Tratcher
Copy link
Member

Tratcher commented Nov 6, 2015

Also https://docs.asp.net/en/latest/publishing/iis.html#common-errors. Most of the bad gateway errors we've seen were the result of installing the incorrect HttpPlatformHandler.

@guardrex
Copy link
Contributor

guardrex commented Nov 6, 2015

@mdmoura Explicitly confirm the version at Control Panel > Programs > Programs and Features, where it will say 1.2 in the name if you have the correct version.

@mdmoura
Copy link
Author

mdmoura commented Nov 8, 2015

@guardrex I checked and I have HTTP Plataform Handler 1.2.1959 installed.

I followed the information you posted and now I get a very strange behavior:

When I click on IIS "Browser website ... " in IIS the browser opens and I see on the browser title "Http Error 502.3 - Bad gateway" for a short moment even if the error is not displayed on the page ... And after that short moment the browser starts to load the website and I see "Waiting for ..." but nothing happens ...

@davidfowl
Copy link
Member

@mdmoura And you're using Kestrel not WebListener right?

@mdmoura
Copy link
Author

mdmoura commented Nov 8, 2015

@davidfowl Yes, I am using Kernel but I found the problem. My configuration was fine but I had on project.json "1.0.0-*" ... It seems there are a few RC1 packages already published but not all so I had a mix of Beta8 and RC1 ...

BTW, will RC1 include a solution for hosting a project on a Virtual Dir instead of using?
app.Map("/virtualdir", (app1) => this.Configure1(app1, env, loggerFactory));

If not I suggest adding the 404 error to Common Errors since this is what I got when not using Map.

@mdmoura mdmoura closed this as completed Nov 8, 2015
@Tratcher
Copy link
Member

Tratcher commented Nov 9, 2015

@mdmoura The vdirs are not fixed for rc1 because we need an update from the HttpPlatformHandler. aspnet/IISIntegration#14. Feel free to send a PR to the docs, or just to add a comment to that page.

@jijiechen
Copy link

I ran into the same issue this morning, and after a few hours' researching, I successfully find something.

In short, the Bad Gateway error is caused by failures during communication between HTTP Platform Handler and the application.

So many reasons can cause this problem, and please do a step by step validation to diagnose:

  • Confirm you've installed the HTTP Platform Handler module (the latest version is 1.2)
  • Confirm your app can successfully be built using dnu build
  • Confirm your have defined a command which can be used to startup in your project.json
  • Confirm in IIS, you mapped the wwwroot of published artifacts to the site, not any other directories
  • Confirm you can run your app run through a command line: something like dnx web or dnx kestrel

After above confirmation, you can follow these steps to deal with your problem:

  1. Check the _logs_ directory, and if some problems reported, follow the instructions;
  2. Try checking Windows event viewer, If you get "Could not create stdoutLogFile", please assign a loose permission requirement for the _logs_ directory.
  3. Try checking Windows event viewer, If you get "Process xxx failed to start. Port = yyy, Error Code = '-2147023829'.", please specify --runtime active option to include runtimes when creating artifacts using the dnu publish command tool.

After each step, do an IIS reseting to confirm if problem solved.

Still get problems? Try to use the stdout to figure out what's happening during the invocation when our apps starts. Edit your wwwroot\web.config file, at httpPlatform section, change value of stdoutLogEnabled attribute to true and save.

Reset IIS and reload the page again. Browse to your approot and find what's wrote in the logs directory. There should be something really helpful. After solving problems, remember to restore your wwwroot\web.config.

For me, I found dnx.exe is not recognized as an internal or external command thing, which means the runtime cannot find dnx. So the fastest way to solve my problem is to include runtime in my artifact. And it seems if your command use WebListener as hosting server, you will get problems when working with Http Platform Handler

Good luck and expecting your experience.

@vladvoinescu
Copy link

@jijiechen could you please elaborate on this:

For me, I found dnx.exe is not recognized as an internal or external command thing, which means the runtime cannot find dnx. So the fastest way to solve my problem is to include runtime in my artifact.

How did you do this? I am having the same issue as you had and I already went through all of the steps that you described so throughly - thank you for that. I do have some issues with the one that solved your problem in the end.

Kind regards,
Vlad

@jijiechen
Copy link

@vladcvoinescu In my last comment, the first part is about verifying your app works correctly; and second part is trying to solve problems that can cause failures on writing output logs or creating the process for launching your app.
So after all those steps, if still get any problems, You will see logs, and diagnose according to the output.

@vladvoinescu
Copy link

@jijiechen Thank you for your response. I went through all the steps with no luck. Stdout logs are created but are empty. I get a lot of those in the Server Manager -> Local Server -> Events: http://imgur.com/7SIufhb

Any ideas?

PS: I just read again your comment and I realized what you meant by including runtime. I will try that now.

@jijiechen
Copy link

@vladcvoinescu Form your image, I can only see a title without details, could you please post them as well?

@vladvoinescu
Copy link

@jijiechen The details for both the Warnings and the Errors are empty: http://imgur.com/HZMFgNv

PS: I opened the Event Viewer and I could see the details there: http://imgur.com/3IE3DCD

@jijiechen
Copy link

From your posted image, I can see the process can not be started.
You can check the process startup command manually:

  1. launch a command prompt or powershell, cd to your wwwroot directory
  2. enter the process startup command and execute, see what happens

You can find the process startup command in your web.config file, processPath attribute of httpPlatform section.

If it successes, then I think if you use your current login credential as application identity for your application pool in IIS, you can make it.
For a production environment, you should not do this. At that time, the cause should be using default identity of application pool cannot launch the process. I suppose including dnx runtime in your published artifacts should solve those process activating problems.

@vladvoinescu
Copy link

I currently have this in my httpPlatform section:
<httpPlatform stdoutLogEnabled="false" processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" startupTimeLimit="3600" />

PS: If I open cmd and go to the directory above wwwroot (the project's directory) and run dnx web, it runs the website perfectly fine. Is this what you meant?

@jijiechen
Copy link

This is an example that runs successfully:

<httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>

In your configuration, you sepcified to use %DNX_PATH% environment variable as processPath and %DNX_ARGS% as arguments.
So please check if they are correctly configured, make it can access those variables from the identity of the application pool. (Or configure your variables at system-wide)

@jijiechen
Copy link

And here is content in the web.cmd, I hope it helps.
The content is generated from the dnu publish command.

@echo off
SET DNX_FOLDER=dnx-clr-win-x64.1.0.0-rc1-update1
SET "LOCAL_DNX=%~dp0runtimes%DNX_FOLDER%\bin\dnx.exe"

IF EXIST %LOCAL_DNX% (
SET "DNX_PATH=%LOCAL_DNX%"
)

for %%a in (%DNX_HOME%) do (
IF EXIST %%a\runtimes%DNX_FOLDER%\bin\dnx.exe (
SET "HOME_DNX=%%a\runtimes%DNX_FOLDER%\bin\dnx.exe"
goto :continue
)
)

:continue

IF "%HOME_DNX%" NEQ "" (
SET "DNX_PATH=%HOME_DNX%"
)

IF "%DNX_PATH%" == "" (
SET "DNX_PATH=dnx.exe"
)

@"%DNX_PATH%" --project "%~dp0packages\live.asp.net\1.0.0\root" --configuration Debug web %*

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants