I want to create urlrewrite url using appcmd for redirecting all requests from
http://
to
https://
I tried to google but nothing found. Could you provide me some basic example?
Got it working with this:
appcmd.exe set config -section:system.webServer/rewrite/rules /+"[name='http_redirect',enabled='True']" /commit:apphost
appcmd.exe set config -section:system.webServer/rewrite/rules.[name='http_redirect'] /match.url:"(.*)" /match.ignoreCase:true /commit:apphost
appcmd.exe set config -section:system.webServer/rewrite/rules.[name='http_redirect'].conditions/add /+"[input='{HTTPS}',pattern='off']" /commit:apphost
appcmd.exe set config -section:system.webServer/rewrite/rules.[name='http_redirect'].action /+"[type='Redirect',url='https://{HOST_NAME}/{R:1}',redirectType='Found']" /commit:apphost
This link can help on building appcmd scripts.
For the benefit of anyone else looking (as I was) you can do the following to insert your new rule at the start, end or a particular position in the list, as just adding it to the end by default may result in the rule not being hit:
appcmd.exe set config -section:system.webServer/rewrite/rules /+"[#start,name='http_redirect',enabled='True']" /commit:apphost
appcmd.exe set config -section:system.webServer/rewrite/rules /+"[#end,name='http_redirect',enabled='True']" /commit:apphost
appcmd.exe set config -section:system.webServer/rewrite/rules /+"[#2,name='http_redirect',enabled='True']" /commit:apphost
Source:
appcmd.exe set config /?
In my case the syntax is slightly different since I wanted to alter a URL Rewrite rule at the root (server) level.
appcmd set config -section:system.webServer/rewrite/globalRules -[name='myRule'].action.url:http://myRewrite /commit:apphost
It took me a long time to figure out the globalRules instead of rules difference.
Related
I created a script using appcmd.exe to setup my FastCGI application in IIS. They work but I am unsure about a few details. Some of the options in the below commands have been shortened for clarity.
Some of the command details start with a slash and some with a dash. Which is the preferred style? Also, I am not clear on which ones require /commit and which do not. Note that I have a delete command so that I can run the script multiple times.
appcmd.exe delete vdir /vdir.name:"Default Web Site/pbcgi"
appcmd.exe add vdir /app.name:"Default Web Site/" /path:/pbcgi /physicalPath:"C:\TopwizWeb"
appcmd.exe set config /section:system.webServer/handlers /accessPolicy:Read,Script,Execute /commit:apphost
appcmd.exe clear config -section:system.webServer/handlers -"[name='TopwizWeb FastCGI']"
appcmd.exe set config -section:system.webServer/handlers /+"[name='TopwizWeb FastCGI', path='*.pbcgi']"
appcmd.exe clear config -section:system.webServer/fastCgi -"[fullPath='C:..\TopwizWeb.exe']"
appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:..\TopwizWeb.exe', maxInstances='4']" /commit:apphost
You have asked, "Some of the command details start with a slash and some with a dash. Which is the preferred style?"
I try to refer to official documents.
Getting Started with AppCmd.exe
AppCmd.exe
The first link shows the use of '/' whereas the second link shows the use of '-' with the parameters of the Appcmd command.
While checking other online articles, I noticed the majority of the article shows examples using '/'.
As both ways are supported, you could prefer which is suitable for you.
If we talk about the /commit then it is used for controlling the location of configuration changes.
What is the value of site name in the following code when we get a error like this as shown
appcmd set config ["SITE_NAME"] /section:system.webServer/directoryBrowse /enabled:true
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
Most likely causes:
A default document is not configured for the requested URL, and directory browsing is not enabled on the server.
Things you can try:
If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists.
Enable directory browsing.
Go to the IIS Express install directory.
Run appcmd set config /section:system.webServer/directoryBrowse /enabled:true to enable directory browsing at the server level.
Run appcmd set config ["SITE_NAME"] /section:system.webServer/directoryBrowse /enabled:true to enable directory browsing at the site level.
Verify that the configuration/system.webServer/directoryBrowse#enabled attribute is set to true in the site or application configuration file.
If you are able to use AppCmd, then use AppCmd list sites to dump out all the configured sites. You'll need to select the correct one (if there are more than one) based on the binding information.
You get this error because the website does not have the 'Directory Browsing' feature enabled.
Firstly you need to check that you install directory browsing feature or not.Then you could enable directory browsing by following ways:
Using IIS manager console window:
1)Open Internet Information Services (IIS) Manager.
2)From the Connection Pane select Site name for which you want to enable directory browsing.
3)From Feature View Select Directory Browsing.
4)In the Actions pane, click Enable.
You could also set this by using the command prompt:
1)Open a command prompt as administrator.
2)Run below command:
appcmd set config "urlsample" /section:system.webServer/directoryBrowse /enabled:true
appcmd set config ["SITE_NAME"] /section:system.webServer/directoryBrowse /enabled:true
In ["SITE_NAME"] you need to specify the name of your site which you set in IIS.
You could also set in web.config file under the system.webserver section:
<directoryBrowse enabled="true" />
You could also refer below article for more detail:
Directory Browse
Regards,
Jalpa.
What needs to be done to modify this script to set allowed extensions by the website and not globally.
appcmd set config /section:requestfiltering /+fileExtensions.[fileextension='string',allowed='true | false']
This is how you target individual sites.
appcmd set config "SITE_NAME_HERE" /section:system.webServer/security/requestFiltering /fileExtensions.[fileExtension='.json'].allowed:true
To set a proxy when using npm I use :
npm config set proxy http://proxy.pro.com:8080
npm config set https-proxy http://proxy.pro.com:8080
I set this with each use of npm in mac terminal. Where should this command be added in order to permanently set the proxy so is available to all instances of terminal ?
I could run a startup script on mac boot but how to ensure the proxy config is available to all instances of terminal ?
You can create a .npmrc file and place the config in there
proxy http://proxy.pro.com:8080
https-proxy http://proxy.pro.com:8080
npm config set https-proxy https://username:pwd#proxy.company.com:8080
npm config set proxy https://username:pwd#proxy.company.com:8080
npm config set sslVerify false
npm config set strict-ssl false
set HTTP_PROXY=http://username:pwd#proxy.company.com:8080
set HTTPS_PROXY=https://username:pwd#proxy.company.com:8080
Permanently set proxy:
Add HTTP_PROXY and HTTPS_PROXY to System environment variables
You could put it in your bash profile, or other shell startup script. So, for example $HOME/.profile.
If you mean, "all instances of Terminal for all users", then you would need to put it in /etc/bashrc.
I believe my work proxy is preventing me from being able to add themes and packages to Atom. From the preferences menu, I get:
Fetching featured packages and themes failed. Hide output…
tunneling socket could not be established, cause=140499728967552:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:766:
Is it possible to make it use my $https_proxy variable? Is there some way to configure it to not use https?
You can configure your proxy settings in ~/.atom/.apmrc (or Atom\resources\app\apm\node_modules\atom-package-manager\.apmrc in Windows). Per the apm README:
If you are using a proxy you can configure apm to use it by setting the https-proxy config in your ~/.atom/.apmrc file like so:
https-proxy = https://9.0.2.1:0
It seems that as of Atom 1.0, there are some components that respect the http-proxy and https-proxy variables, and others that don't. For example, the initial check for the version of Atom works, but the check for packages doesn't seem to respect the http-proxy or https-proxy settings.
I was able to get Atom working with Fiddler as my proxy (on 127.0.0.1:8888) by running the following commands (on Windows):
apm config set proxy http://127.0.0.1:8888
apm config set strict-ssl false
I did not need to set http-proxy or https-proxy. I don't know if these settings have been deprecated or not, but they don't seem to work reliably in 1.0. The setting proxy works (and upgrades itself to TLS 1.2 automatically).
The entirety of my %USERPROFILE%\.atom\.apmrc file is:
strict-ssl=false
proxy=http://127.0.0.1:8888/
I was getting this error on Windows 7 fro Atom 1.0, when trying to look up packages.
In my case the issue was resolved by setting https-proxy variable to use http protocole instead of https. so both of the following parameters have exact same value.
here are the values from ~.atom.apmrc file
proxy=http://[host]:[port]/
https-proxy=http://[host]:[port]/
the answer by #NYCdotNet below that suggested to use
strict-ssl=false
didn't work as i was able to lookup some packages but installation failed with timeout error from GIT.
Atom will use your shell's proxy variables (like $https_proxy) if you start Atom from a shell that has these variables set. You need to have the Atom command line tools installed for that to work.
From a shell, you can simply type atom to open the editor for the current directory. It will use all environment variables from this shell, including the proxy variables.
I find this a lot easier than setting the variables in the config file.
I edited the ~/.atom/.apmrc file to set my proxy as mentioned by #AlexMooney, but still got errors.
The solution was to write
proxy = http://host:port
strict-ssl = false
in that ~/.atom/.apmrc file.
For Windows you can easily configure the https-proxy via command line:
amd config set https-proxy https://9.0.2.1:0
It should be stored under C:\Users\...\.apm in file .apmrc
See userconfig with command
amd config list
To config Proxy for Atom to install new pakage, just open CMD and run these commands:
apm config set strict-ssl false
apm config set proxy your_proxy
apm config set your_proxy
I am working behind a proxy server and spent about half a day on this issue, setting https_proxy as well as http_proxy didn't make a difference.
What did it for me was setting the proxy from the cmd line like so:
apm config set proxy http://myproxyaddress:port
I still can't install packages through Atom's gui, but doing it through the cmd line works fine. That I'll take.
I later realised I could've switched to the wifi and got it to work immediately...