I have a front controller setup on IIS which I need to convert to NGINX on Docker.
Basically on IIS I have a virtual directory /we which maps to the application code at /var/app/we. When file is requested, if its not found, it is rewritten to /we/index.cfm?path_info=/{R:0}.
E.g. if a user requests http://example.com/sub1/test.cfm it is rewritten as http://example.com/index.cfm?path_info=/sub1/test.cfm.
I have tried various things like setting up a virtual directory alias in NGINX like this
location /we {
alias /var/app/we;
}
and then adding a rewrite rule but I just can't get it to work. Can someone please help?
The rule on IIS which I'm trying to convert is below:
<rule name="Redirect the File" enabled="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(flex2gateway|jrunscripts|cfide|cfformgateway|railo-context|files|images|javascripts|miscellaneous|stylesheets|rewrite.cfm|index.cfm)" negate="true" />
</conditions>
<action type="Rewrite" url="/we/index.cfm?path_info=/{R:0}" appendQueryString="true" />
</rule>
You can try the script from this link: iis-to-nginx.
Automated script to convert IIS rewrite rules to nginx rewrite format the code convert rewrite IIS rules to nginx rewrite format, you can import the output into the nginx config file.
Related
I'm trying to rewrite all my URL's to HTTPS but getting this error, not sure what am I doing wrong:
Config Error
This configuration section cannot be used at this path. This happens
when the section is locked at a parent level. Locking is either by
default (overrideModeDefault="Deny"), or set explicitly by a location
tag with overrideMode="Deny" or the legacy allowOverride="false".
web.config:
<rewrite>
<allowedServerVariables>
<add name="HTTPS" />
<add name="X-FORWARDED-PROTO" />
</allowedServerVariables>
<rules>
<rule name="HTTPS_AlwaysOn" patternSyntax="Wildcard">
<match url="*" />
<serverVariables>
<set name="HTTPS" value="on" />
</serverVariables>
<action type="None" />
<conditions>
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" />
</conditions>
</rule>
</rules>
</rewrite>
I have also installed Rewrite module and ARR on Docker container
# Install Url Rewrite
ADD https://download.microsoft.com/download/1/2/8/128E2E22-C1B9-44A4-BE2A-5859ED1D4592/rewrite_amd64_en-US.msi /install/rewrite_amd64_en-US.msi
RUN msiexec.exe /i c:\install\rewrite_amd64_en-US.msi /passive
ADD https://download.microsoft.com/download/A/D/C/ADC4BAF8-A094-47B5-A6F6-CE4C5ED18BF8/ARRv3_setup_amd64_en-us.EXE /install/ARRv3_setup_amd64_en-us.exe
RUN c:\install\ARRv3_setup_amd64_en-us.exe /Q
Build a normal IIS 10 machine for testing first and you should notice the same error, as that allowedServerVariables cannot be in web.config.
Reference
To enable SSL Rewrite simply add this inside:
<rules>
<rule name="SSL Redirect" enabled="true" stopProcessing="true">
<match url="(.*)"/>
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="off"/>
<add input="{HTTP_HOST}" pattern="localhost" negate="true"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
So i'm using iis 8 and trying to redirect all versions of my site to 1.
Say for example:
http://www.osrshub.com
www.osrshub.com
osrshub.com
http://osrshub.com
https://osrshub.com
https://www.osrshub.com
When a user hits any of these links i need it to redirect to 1 main link.
https://www.osrshub.com
Im using windows server 2012
This rule will redirect everything to https://www.osrshub.com:
<rule name="All in one rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="^www\.osrshub\.com$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.osrshub.com/{R:0}" />
</rule>
You need to add this rule in your web.config file
We are running Umbraco 7.4. Due to a corporate security requirement, we need to prevent people from reaching oursite.com/umbraco from anywhere except the server itself as localhost/umbraco. I have tried an IIS rewrite for /umbraco#/ to no avail. I tried an IIS deny rule for /umbraco, but that actually broke some other stuff around our site. Is there some other awesome way to prevent remote access to the Umbraco back office?
I have done a similar thing with IIS rewrite rules where you can only access the back office from a specific set of domains (hence the wildcard matching). You could use this to only allow access from localhost. NOTE, place the rule in the umbraco folder, not the main site web.config. the full web.config contents to place in the umbraco folder is:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Umbraco only from localhost" enabled="true" patternSyntax="Wildcard"
stopProcessing="false">
<match url="*" negate="false" />
<action type="Rewrite" url="/UmbrSubDir404" appendQueryString="false"
logRewrittenUrl="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
<add input="{URL}" pattern="*RestServices/ScheduledPublish*"
negate="true" />
<add input="{URL}" pattern="*umbraco/Api/*" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
We had a security review that revealed that the cookies in our ASP.NET MVC application were not being set as secure, despite having the following setting in web.config:
<httpCookies requireSSL="true" httpOnlyCookies="true" />
The website is not using forms authentication so no need for <forms requireSSL="true"> setting.
The website is hosted on an AWS app server and is accessed via an ELB. Internally on the app server the website is HTTP but externally it is HTTPS.
I've tried to implement a solution found here:
http://www.jamescrowley.co.uk/2014/03/07/ssl-termination-and-secure-cookiesrequiressl-with-asp-net-forms-authentication/
Added the following rewrite rules to this to web.config:
<rewrite>
<rules>
<rule name="HTTPS_AlwaysOn" patternSyntax="Wildcard">
<match url="*" />
<serverVariables>
<set name="HTTPS" value="on" />
</serverVariables>
<action type="None" />
<conditions>
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" />
</conditions>
</rule>
</rules>
</rewrite>
And added HTTPS variable to the applicationHost.config to contain:
<rewrite>
<allowedServerVariables>
<add name="HTTPS" />
</allowedServerVariables>
</rewrite>
Unfortunately this causes the ELB to fail. When speaking to our internal AWS support team they say this is because the ELB health check is failing. There is a health.html page in the root of the website. Is there a way of applying a condition to the above so that it ignores this for the health.html page which the ELB uses? I'm new to rewrite rules so not fully versed in the syntax and the way they work.
I can't test this yet, but in theory I think you would just need to change your conditions:
<conditions logicalGrouping="MatchAll" >
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" />
<add input="{REQUEST_URI}" negate="true" pattern="^/health.html$" ignoreCase="true" />
</conditions>
I have 2 domain names: domain1.com and domain2.com.
I am using the redirect script in the root to redirect each domain to it's own folder. This is working correctly. The problem I am having is that when it redirects to a folder it shows the folder name in the url after the domain name: (domain1.com/subfolder1).
My question is how to remove the ""subfolder1" from the URL?
I've tried to find a solution to this and found some guides out there but none seem to work. I have hosted nopcommerce in "subfolder1"
My web.config file as follows
<rewrite>
<rules>
<rule name="rule1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain1.com$" />
<add input="{HTTP_HOST}" pattern="^www.domain1.com$" />
<add input="{PATH_INFO}" pattern="^/subfolder1/" negate="true" />
</conditions>
<action type="Redirect" url="\subfolder1\{R:1}" />
</rule>
</rules>
</rewrite>