URLs breaking in WildFly on static served web content - linux

I was given a weird requirement of hosting small campaign websites with 5-6 pages written in Angular and some APIs these websites can interact with. Everything coming from a WildFly instance.
I configured the paths and handlers using WildFly/Jboss' Undertow subsystem for each of these campaign portals. Their home page shows up when tried to access the the server with the path. Here's the example:
<subsystem xmlns="urn:jboss:domain:undertow:11.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other" statistics-enabled="${wildfly.undertow.statistics-enabled:${wildfly.statistics-enabled:false}}">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
<https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
<host name="default-host" alias="localhost">
<location name="/app1" handler="app1"/>
<location name="/app2" handler="app2"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
</host>
</server>
<servlet-container name="default">
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name="app1" path="${jboss.home.dir}/app1" directory-listing="true"/>
<file name="app2" path="${jboss.home.dir}/app2" directory-listing="true"/>
</handlers>
</subsystem>
However if I click any of the links inside the landing/index page within these apps, I get 404 - Not Found.
Ex: https://myhost.mydomain.com/app1 -> Gives the landing/index page.
Any link I click within that page, for instance, if there is 'faqs' and the URL is https://myhost.mydomain.com/app1/faqs, it resolves fine to that path but I am getting 404 - Not found.
Looking for a way to make this work.

Related

Is there a way to add a authentication in wildfly file handler

I am using a WildFly(version - 19) to do file directory listing using below configuration.
<subsystem xmlns="urn:jboss:domain:undertow:10.0">
...
<host name="default-host" alias="localhost">
<location name="/SoftwareRepository" handler="SoftwareRepo"/>
</host>
...
<handlers>
<file name="SoftwareRepo" path = "<Path to Directory>" case-sensitive="false" directory-listing="true"/>
</handlers>
</subsystem>
This works fine for me and listing the file list for the respective configured path. B
Now, my worry is about authentication. The file directory listing is happening when I access the URL but without any authentication.
How to add any authentication mechanism to do this file handler?

Apache tomcat : URL based redirection partially works

I am working on deploying multiple webapps in single tomcat instance in which the webapp to be called depends upon the URL the user has called. So if user calls www.domain-one.com, then firstapp.war is the webapp the user is looking for and that will be shown to the user.
I have had partial luck with this. Right now, if I call www.domain-one.com, nothing happens, but if I call www.domain-one.com/firstapp, then correct webapp is called.
I just want to get rid of that firstapp in the context-path. How can I achieve that.
Here is my config :
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"/>
<Host name="www.domain-one.com" autodeploy="true" unpackWARs="true" appBase="/war/firstapp"/>
<Host name="www.domain-two.com" autodeploy="true" unpackWARs="true" appBase="/war/secondapp"/>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
There are only two webapps for now in my webapps folder, neither a ROOT.war. I hope this information is enough. Kindly let me know why is this problem happening. Thanks a lot. :-)
Depending on your tomcat majour release, check here:
Tomcat 6 - https://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html
Tomcat 7 - https://tomcat.apache.org/tomcat-7.0-doc/virtual-hosting-howto.html
Tomcat 8 - https://tomcat.apache.org/tomcat-8.0-doc/virtual-hosting-howto.html
It's really straightforward and let's you get rid of the context path too.
I used a different config which solved this problem :
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"/>
<Host name="firstdomain.com" autoDeploy="true" unpackWARs="true" appBase="firstdomain_webapps">
<Alias>www.firstdomain.com</Alias>
<Context path=""/>
</Host>
<Host name="seconddomain.com" autoDeploy="true" unpackWARs="true" appBase="seconddomain_webapps">
<Alias>www.seconddomain.com</Alias>
<Context path=""/>
</Host>
This config worked for me, and solved my problem.

xdt:Transform fails to change mailsettings

Before I start I would like to say that I have read and tried all methods/solutions I can find on this and other forums to no avail.
I have a simple mail setting entry in my webconfig that I want transformed when publishing to test environment etc.
This is the main config that uses my local settings
<system.net>
<mailSettings>
<smtp from="p.carey#sentinelwater.co.uk">
<network host="SENTINEL-SBS" port="25" />
</smtp>
</mailSettings>
</system.net>
and this is one of the attempted transforms
<system.net>
<mailSettings>
<smtp from="noreply#test.managemywater.co.uk" xdt:Transform="Replace">
<network xdt:Transform="Replace" host="localhost" port="25" />
</smtp>
</mailSettings>
</system.net>
It simply fails on replacing 'host' with localhost and maintains SENTINEL-SBS. I have no idea if it attempts to replace 'from'.
I have run out of ideas and will have to resort to translating Japanese forums now!!!
No doubt there is a simple answer but I'll be damned if I can find it.
I have an addition transform for the connection string using 'add name' and that works fine.

Allow loading of JSON files in Visual Studio Express 2013 for Web

I have the problem, that the IIS from Visual Studio Express 2013 for Web doesn't allow the loading of *.json files. When trying to load a *.json file I get a 403 Forbidden and a help page how to configure the IIS allow the loading of JSON files, but don't know what to do with this information / where the IIS is even located.
This is the error page:
HTTP Error 404.3 - Not Found The page you are requesting cannot be
served because of the extension configuration. If the page is a
script, add a handler. If the file should be downloaded, add a MIME
map.
Most likely causes: It is possible that a handler mapping is missing.
By default, the static file handler processes all content. The feature
you are trying to use may not be installed. The appropriate MIME map
is not enabled for the Web site or application. (Warning: Do not
create a MIME map for content that users should not download, such as
.ASPX pages or .config files.) If ASP.NET is not installed.
Things you can try: In system.webServer/handlers: Ensure that the
expected handler for the current page is mapped. Pay extra attention
to preconditions (for example, runtimeVersion, pipelineMode, bitness)
and compare them to the settings for your application pool. Pay extra
attention to typographical errors in the expected handler line. Please
verify that the feature you are trying to use is installed. Verify
that the MIME map is enabled or add the MIME map for the Web site
using the command-line tool appcmd.exe. To set a MIME type, run the
following command in the IIS Express install directory: appcmd set
config /section:staticContent
/+[fileExtension='string',mimeType='string'] The variable
fileExtension string is the file name extension and the variable
mimeType string is the file type description. For example, to add a
MIME map for a file which has the extension ".xyz": appcmd set config
/section:staticContent /+[fileExtension='.xyz',mimeType='text/plain']
Warning: Ensure that this MIME mapping is needed for your Web server
before adding it to the list. Configuration files such as .CONFIG or
dynamic scripting pages such as .ASP or .ASPX, should not be
downloaded directly and should always be processed through a handler.
Other files such as database files or those used to store
configuration, like .XML or .MDF, are sometimes used to store
configuration information. Determine if clients can download these
file types before enabling them. Install ASP.NET. Check the failed
request tracing logs for additional information about this error. For
more information, click here.
Detailed Error Information: Module StaticFileModule Notification
ExecuteRequestHandler Handler StaticFile Error Code 0x80070032
Requested URL http: //localhost:64107/Settings/Settings.json
Physical Path D:\GIT\RepoP_Paneon\Settings\Settings.json Logon
Method Anonymous Logon User Anonymous Request Tracing Directory
C:\Users\stefank\Documents\IISExpress\TraceLogFiles\REPOP_PANEON
More Information: This error occurs when the file extension of the
requested URL is for a MIME type that is not configured on the server.
You can add a MIME type for the file extension for files that are not
dynamic scripting pages, database, or configuration files. Process
those file types using a handler. You should not allows direct
downloads of dynamic scripting pages, database or configuration files.
View more information ยป
After some more googling, and experimenting I found out, that you have to define IIS settings in the Web.config.
After adding the following configuration:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
it works like a charm.
Full setup file example:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
Better add remove tag in case future IIS has build in json support. This is my web.config section of mimeMap.
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<remove fileExtension=".json" />
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
<system.webServer>
Open CMD with administrator privilages.
Go to:
cd C:\Program Files\IIS Express
or
cd C:\Program Files (x86)\IIS Express
Run command:
appcmd set config /section:staticContent /+[fileExtension='JSON',mimeType='application/x-javascript']
We may need to distinguish the Visual Studio development environment (with IIS Express) from local IIS and a remote server (like Azure WebSites). To specifically target IIS Express, for example, we edit %USERPROFILE%\Documents\IISExpress\config\applicationhost.config under system.webServer/staticContent:
<mimeMap fileExtension=".json" mimeType="application/javascript" />
I need to make this distinction because my local (intranet) IIS already has the JSON mime type defined. So when I deploy to Azure websites I use this transformation in Web.Release.config:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/javascript" xdt:Transform="Insert" />
</staticContent>
</system.webServer>

IISExpress Log File Location

IISExpress writes log and configuration data to pre-determined location out of the box.
The directory is an "IISExpress" directory stored in a user's Documents directory.
In the directory is stored the following folders files underneath.
Config
Logs
TraceLogFiles
The location of my home directory is on a network share, determined by group policy
Currently we are encountering scenarios where visual studio locks up when stopping debugging Silverlight applications using IIS Express.
I was looking to change the location for the log & configuration data for IISExpress to see if this fixes the problem of visual studio locking up. Is it possible to change the default location of log & config files ?
1 . By default applicationhost.config file defines following two log file locations. Here IIS_USER_HOME would be expanded as %userprofile%\documents\IISExpress\.
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" />
</siteDefaults>
You can update above directory paths to change the log file locations.
2 . If you are running IIS Express from command line, you can use '/config' switch to provide configuration file of your choice. Following link may help you http://learn.iis.net/page.aspx/870/running-iis-express-from-the-command-line/
http://www.iis.net/configreference/system.applicationhost/sites/sitedefaults
<configuration>
<system.applicationHost>
<sites>
<siteDefaults>
<logFile
logFormat="W3C"
directory="%SystemDrive%\inetpub\logs\LogFiles"
enabled="true"
/>
<traceFailedRequestsLogging
enabled="true"
directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles"
maxLogFiles="20"
/>
<limits connectionTimeout="00:01:00" />
<ftpServer serverAutoStart="true" />
<bindings>
<binding
protocol="http"
bindingInformation="127.0.0.1:8080:"
/>
</bindings>
</siteDefaults>
</sites>
</system.applicationHost>
</configuration>
I find web.config documentation is a messy. It is therefore better to provide a complete parent history than a floating snippet with the expectation that the reader naturally knows where it goes.
By default it will be in:
C:\Users\ user_name \Documents\IISExpress\Logs\

Resources