Deploying a Vue app to IIS under the Default web site - vue.js

I was successfully able to get a Vue app working in iis at the root level with a port(8181),
but I need to get it working under the Default Web Site in iis (port 80)
To test this I started a brand new website with the Vs19 template. ( should have used vue scaffolding, will try that tomorrow, done, reproduces the same error)
Got it up and running under npm run serve.
Ran npm run build
Went to IIS, added a new app under Default Web Site" called VuejsApp2 pointing to the dist folder under the main folder.
Copied the default web.config for a vue app:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" path="/survey/notfound" responseMode="ExecuteURL" />
<error statusCode="500" path="/survey/error" responseMode="ExecuteURL" />
</httpErrors>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Went to the Dist folder and set security user "Everyone" and gave it full access to the folder (yes I know, it's a test)
Made sure sure URl re-write was installed (required to get app working at base) by looking under installed apps
Pointed the app in IIS to the same App pool that worked for the other app (integrated, no
When I navigate to the app in chrome at http://localhost/VuejsApp2
I get a 503 service is not available error
I figure it's something basic, but all the tutorials I've found to host vue in iis, this is all that's listed to do, I found a SO question on the same topic, but it had no answers...
Other SO question with no answer
I read that 503 in IIS meant that the app pool was stopped due to multiple crashes, but the app pool shows started not stopped.
UPDATE:
I added this to the web.config for my basic empty vue app and it still gets 503 error
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" path="/survey/notfound" responseMode="ExecuteURL" />
<error statusCode="500" path="/survey/error" responseMode="ExecuteURL" />
</httpErrors>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
On my original app, I did it and I"m getting a different unrelated error. so maybe it helped?

I would check your rewrite rule, I think you're getting an error due to too many redirects.
You're sending anything intended to be picked up by VueRouter to the root of your site, rather than to your index.html. Change your rewrite rule to this
<action type="Rewrite" url="/index.html" />
I think that might help solve your problem

Related

The .NET Core feature AllowedHosts is not working

I have a micro service built on .net core v3 and hosted in the ATIKA domain which is on a virtual machine of Azure. I want to access hosted API from the IVKLA domain only and other than this domain should get 400 status code.
So in allow host is taken care in the appsettings file
"AllowedHosts": "IVKLA.com"
Even with this setting, however, I am getting 400 status code from any Postman request made from IVKLA domain computers.
I have tried other forum posts but still did not got any proper answer.
The information below was last updated on October 21, 2022.
As suggested, I have tried using URL ReWrite in IIS server. I Was able to block the IP and getting 403 forbidden status.
But when I have try to white list an IP I am getting
"500URL Rewrite Module Error"
This is the URL rewrite from web.config
<rewrite>
<rewriteMaps>
<rewriteMap name="Authorized Admin IPs">
<add key="1.2.3.4" value="1" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Authorized admin" patternSyntax="Wildcard">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{Authorized Admin IPs:{REMOTE_ADDR}}" pattern="1" />
<add input="{REMOTE_ADDR}" pattern="*.*.*.*" />
</conditions>
<serverVariables>
<set name="HTTP_X_AUTHORIZED_ADMIN" value="yes" />
</serverVariables>
<action type="None" />
</rule>
<rule name="un Authorized users" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern=".*" />
<add input="{HTTP_X_AUTHORIZED_ADMIN}" pattern="yes" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="forbidden" statusDescription="forbidden" />
</rule>
</rules>
</rewrite>

deploy a Vue+Electron application for both desktop and web application

I have used this template for developing my application which is a Vue app with an Electron builder. Now I have a problem:
I need to build production and deploy my project once as an electron package and another time for a web application hosted on a web server. I do not want to separate it into two repositories as well. Do anybody have any suggestions?
I have tried using dist folder as root folder of website and I have added a web.config file as follow to the root but I am getting an error.
web.config file content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Vue" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="^/api/.*" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
the error on IIS:
Yes, you need to install url rewrite module on IIS. Otherwise, IIS won't understand what <rewrite> <rules> <rule name="Vue" stopProcessing="true"> means in web.config.
Download it from here

why do File downloads get redirected to home page with vue.js history mode enabled on IIS

I have the following setup: on IIS
A Vue.js app # https://localhost/some-app/
I need to be able to download files from an inner folder:
https://localhost/some-app/pdf-reports/test.pdf
With vue.js history mode enabled and configured,
why do requests for inner folders or files get redirected to the home page?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

How to run vuejs files on IIS

So am using a vueJS Example as a demo for learning purposes which uses a requirejs-vue as a component loader.
when i run the server on Live-Server extension of VS-code (a simple http server), it run correctly with no problems.
However, when i run this example on IIS server (version 8.5) on windows 8.1, it through 404 Error app.vue does not exist.
Failed to load resource: the server responded with a status of 404 (Not Found)
and in the Network devtool, i can see that every module is loaded correctly, except for *.vue files,
VueJS Example :
https://plnkr.co/edit/Y2cEa3?preview
Web Config for IIS that am using:
https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
PS: i have also run an other example that uses http-vue-loader instead of requirejs-vue and IIS still throwing the same error.
We need to set mimeType for the “.vue” extension file to use httpvueloader/requiresjs_vue.
In addition, we could manually add it to a Web.Config file, which can be recognized by IIS.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".vue" mimeType="application/javascript"/>
</staticContent>
</system.webServer>
</configuration>
Feel free to let me know if the problem still exists.

Reverse proxy apache for TeamCity

I need to redirect a cname to a port.
I have Teamcity running on my server (at port 8111), I want to make teamcity.mydomain.com be redirected to mydomain.com:8111. So I will just need to type teamcity.mydomain.com to get into teamcity server.
I have read that reverse proxy from apache would do it for me, but so far I could not get it setup correctly.
ps.: it works when I do mydomain.com:8111.
I think something like this should work:
ProxyPass / http://example.org:8111/
ProxyPassReverse / http://example.org:8111/
ProxyPreserveHost On
Make sure mod_proxy is enabled to.
If you are running on Windows, and have IIS installed you can do this with IIS by installing the Application Request Routing module, and the Rewrite module. Once you do that, here is are the rewrite rules for your web.config. This rewrites all request for http://example.com to http://example.com:8080.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="CIReverseProxyInboundRule" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://example.com:8080/{R:1}" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
</rule>
</rules>
<outboundRules>
<rule name="CIReverseProxyOutboundRule" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^http(s)?://example.com:8080/(.*)" />
<action type="Rewrite" value="http{R:1}://example.com/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>