Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
CommandBox's web server supports enabling Basic Auth on your sites.
server set web.basicAuth.enabled=true
server set web.basicAuth.users.brad=pass
server set web.basicAuth.users.luis=pass2That will create the following data in your server.json, which will be picked up the next time you start your server.
{
"web":{
"basicAuth":{
"users":{
"brad":"pass",
"luis":"pass2"
},
"enabled":"true"
}
}
}CommandBox allows you full control over the servers you start. This includes the port and host, custom JVM args, URL rewriting, web aliases, custom error pages, and custom welcome files.
Configuration can be set at several different levels:
Passed as parameters to the server start command
Stored in a server.json file for that server
Global defaults in the server.defaults config setting
Internal defaults from the ServerService
Settings will be used in that order. Also, any parameters passed to the start command will automatically be saved to your server.json file unless you pass the --noSaveSettings flag.
A lot of settings used to start a server involve file paths. Paths starting with a drive letter like C:/, a UNC network path like \\, or a leading slash like / are considered absolute paths and will not be expanded. Try to avoid absolute paths if you want to make your server config portable.
Paths that start with a file/folder name like foo/bar.jar or ../../lib/my.jar are relative and the root folder that they are relative to depends on where there are specified.
If the path is passed as a parameter to the start command, the path is relative to the current working directory
If the path is in the server.json file, it is relative to the folder containing the JSON file. (Remember the server.json doesn't have to be in the web root!)
If the path is in a global server.defaults config setting, it is relative to the web root of the server.
The default welcome files are the usual index.cfm, index.htm, index.html, etc but you can override this with the welcomeFiles setting in your server.json by providing a comma-delimited list of files that you would like CommandBox to look for when a user hits a directory on a running server.
server set web.welcomeFiles='go.cfm,main.cfm,index.html'This setting is a complete override of the defaults, so you need to specify the full list.
By default, a CommandBox server will not show the contents of a directory that doesn't have an index file. You can enable directory browsing for a single server with
server set web.directoryBrowsing=trueAnd you can enable it for all servers by default with
config set server.defaults.web.directoryBrowsing=trueCommandBox allows you to create web aliases for the web server that are similar to virtual directories. The alias path is relative to the web root, but can point to any folder on the hard drive. Aliases can be used for static or CFM files.
To configure aliases for your server, create an object under web called aliases. The keys are the web-accessible virtual paths and the corresponding values are the relative or absolute path to the folder the alias points to.
Here's what your server.json might look like.
Here's how to create aliases from the server set command:
info On Adobe ColdFusion servers, .cfm files will be run automatically from inside an aliases directory. On Railo and Lucee servers, you'll need to create a CF mapping that maps the alias name and path for .cfm files to work.
You can customize the error page that CommandBox servers return. You can have a setting for each status code including a default error page to be used if no other setting applies.
Create an errorPages object inside the web object in your server.json where each key is the status code integer or the word default and the value is a relative (to the web root) path to be loaded for that status code.
This is what you server.json might look like:
You can set error pages via the server set command like this:
If your error page points to a CFM file, you can get access to the original path being accessed for 404s and the error that was thrown for 500s. To see all the request headers that are available, use the following snippet of code:
An example of getting the original missing path in a 404 would look like this:
{
"web" : {
"aliases" : {
"/foo" : "bar",
"/js" : "C:\static\shared\javascript"
}
}
}server set web.aliases./foo = bar
server set web.aliases./js = C:\static\shared\javascript{
"web" : {
"errorPages" : {
"404" : "/path/to/404.html",
"500" : "/path/to/500.html",
"default" : "/path/to/default.html"
}
}
}server set web.errorPages.404=/missing.htmreq = getPageContext().getRequest();
names = req.getAttributeNames();
while( names.hasMoreElements() ) {
name = names.nextElement();
writeDump( name & ' = ' & req.getAttribute( name ) );
}var originalPath = getPageContext().getRequest().getAttribute( "javax.servlet.error.request_uri" );If you have custom jar files that you want to be available to a server, we recommend you use the this.javaSettings functionality in your Application.cfc to load those jars. If that isn't an option for you, or you want to include libs for a JDBC drivers then we offer a feature for you to specify a list of directories for which CommandBox will load jars from. This prevents you from worrying about getting your jars inside the WEB-INF/lib which starts fresh anytime you forget a server.
To load in your jar files, the first method is to use the libDirs parameter to the server start command.
server start libDirs=path/to/libs,another/path/to/libsAnd the way to specify this in a portable manner in your `server.json` is like so:
server set app.libDirs=path/to/libs,another/path/to/libs
server startRemember, paths to the start command are relative to your current working directory and paths in your server.json file are relative to the folder that the server.json file lives in. Absolute paths work the same everywhere.
Have a bunch of servers and they ALL need the same jars, you can add your `libDirs` to the global server defaults config settings. Your global lib directories won't be overwritten by server-level config dirs, but instead appended to. Relative paths in your config settings are relative to the respective web root of the server. CommandBox will also ignore missing lib dirs to give you some flexibility in this.
config set servers.defaults.app.libDirs=/path/to/global/libsThe following JVM Args are supported when starting the embedded server.
You can set the max heap size the server is allowed to have (-Xmx) by passing the heapSize parameter to the start command. This parameter is always specified as megabytes.
In server.json
You can set the starting heap size for the server (-Xms) by passing the minHeapSize parameter to the start command. This parameter is always specified as megabytes.
In server.json
You can specify ad-hoc JVM args for the server with the JVMArgs parameter.
In server.json
You can specify ad-hoc options for the underlying Runwar library using the RunwarArgs parameter.
In server.json
start heapSize=1024server set JVM.heapSize=1024
server show JVM.heapSizestart minHeapSize=1024server set JVM.minHeapSize=1024
server show JVM.minHeapSizestart JVMArgs="-XX:MaxGCPauseMillis\=200"server set JVM.args="-XX:MaxGCPauseMillis\=200"
server show JVM.argsstart RunwarArgs="--sendfile-enable false"server set runwar.args="--sendfile-enable false"
server show runwar.argsThe built in REST implementation in Adobe ColdFusion and Lucee is usually something you either love or hate. If you love it, you can enable it and customize the paths so it doesn't collide with your app's routes. if you hate it, you can turn it off. The REST servlet will be disabled unless you include a setting like so:
server set app.restMappings=/rest/*,/api/*Note that the above setting will take over any URLs starting with /rest or api and you cannot use those routes or folders in your code. This is why it's handy to be able to modify or remove these. On a typical server, this is done via the web.xml, but CommandBox will do it all for you with just the setting above.
The web server in CommandBox is capable of enabling GZIp compression to reduce the size of HTTP responses. To enable GZip compress on your CommandBox server, add a web.gzipEnable setting in your server.json file.
server set web.gzipEnable=trueOnce you start using the embedded server for your development projects, you may wish to enable URL rewriting. Rewrites are used by most popular frameworks to do things like add the index.cfm back into SES URLs.
You may be used to configuring URL rewrites in Apache or IIS, but rewrites are also possible in CommandBox's embedded server via a Tuckey servlet filter.
We've already added the required jars and created a default rewrite XML file that will work out-of-the-box with the ColdBox MVC Platform. To enable rewrites, start your server with the --rewritesEnable flag.
http://tuckey.org/urlrewrite/manual/4.0/index.html
start --rewritesEnableNow URLs like
http://localhost/index.cfm/maincan now simply be
http://localhost/mainIn server.json
server set web.rewrites.enable=true
server show web.rewrites.enableinfo The default rewrite file can be found in
~\.CommandBox\cfml\system\config\urlrewrite.xml
If you want to customize your rewrite rules, just create your own XML file and specify it when starting the server with the rewritesConfig parameter. Here we have a simple rewrite rule that redirects /foo to /index.cfm
customRewrites.xml
<?xml version="1.0" encoding="utf-8"?>
<urlrewrite>
<!-- this will redirect the user from /foo to /index.cfm -->
<rule>
<from>^/foo$</from>
<to type="redirect">/index.cfm</to>
</rule>
<!-- internally redirect the requested URL from /gallery to /index.cfm?page=gallery with query string appended -->
<rule>
<from>^/gallery</from>
<to type="passthrough" qsappend="true">/index.cfm?page=gallery</to>
</rule>
</urlrewrite>Then, fire up your server with its custom rewrite rules:
start --rewritesEnable rewritesConfig=customRewrites.xmlIn server.json
server set web.rewrites.enable=true
server set web.rewrites.config=customRewrites.xml
server show web.rewrites.enable
server show web.rewrites.configYou can place your custom rewrite rule wherever you like, and refer to it by using either a relative path or an absolute path. CommandBox will start looking relative to where the server.json file resides.
server set web.rewrites.enable=true
server set web.rewrites.config=/my/custom/path/customRewrites.xmlor
server set web.rewrites.enable=true
server set web.rewrites.config=~\.CommandBox\cfml\system\config\customRewrites.xmlIf you're coming from Apache, Tuckey supports a large subset of the mod_rewrite style rules like what you would put in .htaccess. You can simply put your rules in a file named .htacess and point the web.rewrites.config property to that file.
Note: The name of the file matters with mod_rewrite-style rules. It must be called .htaccess. With xml rewrites, the filename is not important, only the content.
Here are some simple rewrite rules:
RewriteEngine on
RewriteRule ^/foo/ /
# Defend your computer from some worm attacks
RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]
# Redirect Robots to a cfm version of your robots.txt
RewriteRule ^/robots\.txt /robots.cfm
# Change your default cfm file to index.cfm
RewriteRule ^/default.cfm /index.cfm [I,RP,L]
RewriteRule ^/default.cfm((\?.+)|())$ /index.cfm$1 [I,RP,L]
RewriteRule ^/News.html((\?.+)|())$ /News/index.cfm$1 [I,RP,L]
# redirect mozilla to another area
RewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
RewriteRule ^/no-moz-here$ /homepage.max.html [L]Please see the docs here on what's supported:
info For more information on custom rewrite rules, consult the Tuckey docs.
Your servers come ready to accept SES-style URLs where any text after the file name will show up in the cgi.path_info. If rewrites are enabled, the index.cfm can be omitted.
site.com/index.cfm/home/loginSES URLs will also work in a sub directory, which used to only work on a "standard" Adobe CF Tomcat install. Please note, in order to hide the index.cfm in a subfolder, you'll need a custom rewrite rule.
site.com/myFolder/index.cfm/home/loginThe Tuckey Rewrite engine has debug and trace level logging that can help you troubleshoot why your rewrite rules aren't (or are) firing. To view these logs, simply start your server with the --debug or --trace flags. Trace shows more details than debug. These options work best when starting in --console mode so you can watch the server logs as you hit the site. Alternatively, you can follow the server's logs with the server log --follow command.
start --debug
server log --followThe Tuckey Rewrite library that CommandBox uses under the hood. It has some extra settings that CommandBox allows you to use.
To monitor your custom rewrite file for changes without needing to restart the server, use this setting.
server set web.rewrites.configReloadSeconds=30To enable the inbuilt Tuckey status page, use the following setting. Note, debug mode needs to be turned on for the Tuckey status page to work. Also, you'll need to customize your rewrite file if you use a path other than /tuckey-status.
server set web.rewrites.statusPath=/tuckey-statusThe start command will scan your system and find a random port that is not currently in use to start the server on. This ensures that multiple embedded servers can run at the same time on the same host without collisions. Ensure any redirects in your applications take the port into account.
You may want to set a specific port to use-- even port 80 if nothing else is using it. Pass the HTTP port parameter to the start command like so:
start port=8080It is also possible to save the default port in your server.json. Add a web.http.port property, or issue the following command:
server set web.http.port=8080
server show web.http.portNow every time you start your server, the same port will be used.
If the server won't start or is unreachable, make sure it's port is free with your operating system's netstat command. On Unix-based OS's:
$> netstat -pan | grep 80You can start your server to listen for SSL connections too.
start SSLEnable=true SSLPort=443server set web.SSL.enable=true
server set web.SSL.port=8080
server show web.SSL.enable
server show web.SSL.portThis will enable SSL without an approved SSL certificate. If you need an official certificate so you don't have to confirm your SSL connection you can add these entries
server set web.SSL.certFile=/path/to/dev_mydomain_ext.crt
server set web.SSL.keyFile=/path/to/dev_mydomain_ext.keyAlthough free certificates are available (e.g LetsEncrypt) this is not very convenient, because these certs are valid only for three months. Automatic renewal it is difficult if your dev site is not accessible from the web. For a few dollars a year (< 10) you can apply for a domain validated certificate from companies like Comodo, RapidSSL, Trustwave, Digicert, Geotrust and others or a reseller for these certs. For a domain validated certificate you need a valid domain which is under your control which means (depending on provider):
mail is sent to domain owner
or mail is sent to well-known administrative contact in the domain, e.g. (admin@, postmaster@, etc.)
or you can publish a DNS TXT record
So, now you have a valid domain, you have to generate a SSL key and a SSL Certificate Signing Request. With the CSR you can apply for the certificate. Generating a key and CSR with openSSL
openssl req -utf8 -nodes -sha256 -newkey rsa:2048 -keyout dev_mydomain_com.key -out dev_mydomain_com.csrThis will generate output and some questions, and will finally result in a key file named dev_mydomain_com.key and a certificate signing request (csr) named dev_mydomain_com.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:NL
State or Province Name (full name) [Some-State]:YourState
Locality Name (eg, city) []:YourCity
Organization Name (eg, company) [Internet Widgits Pty Ltd]:YourCompany
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:dev.mydomain.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:You have to enter Country Name, State and City. Organization Name is preferably the same as the domain owner. Organizational Unit Name will not be checked, so enter something simple such as ICT Common Name is the hostname for your site, such as dev.mydomain.com You can skip Email Adress and optional company name. For development you don't need a challenge password, which means your key file is NOT protected. But don't give this key to others or protect it with a challenge password. If you protect your key you have to server set web.SSL.keyPass=MyChallengePassword Now you have a CSR, which you can submit at your SSL provider. They will send you a certificate file (*.csr), and probably one or more intermediate certificates. Create a new my.csr file and copy everything from your certificate file into it, and append the intermediate certificate(s). Now you have a valid my.csr certificate file and a key file. Place both files in a location accessible for your commandbox and enter the corresponding paths to web.SSL.certFile and web.SSL.keyFile
You can start your server to listen for AJP connections too.
start AJPEnable=true AJPPort=8009server set web.AJP.enable=true
server set web.AJP.port=8009
server show web.AJP.enable
server show web.AJP.portYour application may rely on a specific host name other than the default of 127.0.0.1. You can set the host to anything you like, but you must add a host file entry that resolves your host name to an IP address assigned to your network adapter (usually 127.0.0.1)
start host=mycoolsite.localIf you have multiple IP addresses assigned to your PC, you can bind the server to a specific IP using the host parameter.
start host=192.168.10.15 port=80A server configuration can only have one host entry. If you require your server to be available on multiple IP addresses of the machine it runs on, you can set the host to 0.0.0.0. This will effectively bind the server to all network interfaces (including local).
start host=0.0.0.0 port=80Or save in server.json
server set web.host=mycoolsite.local
server show web.hostBy default, CommandBox will open your browser with the host and port of the server. You can customize the exact URL that opens. This setting will be appended to the current host and port.
server set openBrowserURL=/bar.cfmOr you can completely override the URL if your setting starts with http://.
server set openBrowserURL=http://127.0.0.1:59715/test.cfmBy Default, your servers start using the same version of Java that the CommandBox CLI is using. For people needing to run Adobe ColdFusion 9, or who just want to do some testing on different JREs, you can point each of your servers at a custom JRE and CommandBox will use it when starting the server.
if you already have a JRE downloaded somewhere on your hard drive, you can manually point the server at it, or you can simply tell CommandBox which version of java you'd like, at it will automatically download that version of OpenJDK for your server to use (if it's not already downloaded)
Point CommandBox to an existing java install like so:
server set jvm.javaHome="C:\Program Files\Java\jdk1.8.0_25"To set the default version of Java for all the servers you start on your machine, use the global config setting defaults.
config set server.defaults.jvm.javaHome="C:\Program Files\Java\jdk1.8.0_25"To let CommandBox take over and acquire Java for you, pass an installation endpoint ID to the start command
server start javaVersion=openjdk8or set it in your server.json
server set jvm.javaVersion=openjdk8or set a default for all servers
config set server.defaults.jvm.javaVersion=openjdk8To review what possible IDs you can use to dial in your exact Java version, read the docs on our Java endpoint. You don't need to manually install Java-- CommandBox will do that for you. You just need to provide the ID so CommandBox knows what you want.
To make it easier for you to manage the Java installations CommandBox makes for you, we have a namespace of commands you can use. The Java versions CommandBox installs automatically for your servers to use are stored in a folder under your CommandBox home. CommandBox manages this folder for you. You can change where the system Java installation go like so:
config set server.javaInstallDirectory=C:/path/to/JREs/Search the AdoptOpenJDk API for available versions of Java for you to use.
java search version=openjdk8You can filter the version, jvm, os, CPU arch, type, and release. Most of those parameters default to match your local system. For instance, running this command on Windows will only return Windows versions. To open up the search, pass nothing to that filter.
java search version=openjdk8 os=List the installed Java installations for you to start servers with. If you have set a global default Java version it will be marked in the list.
java listYou may change the global default Java version for your servers with this command.
server java setDefault openjdk11The ID follows the format from the Java endpoint. If the version you set as the default isn't installed yet, CommandBox will install it for you the next time a server starts or you can use the --install flag.
You can pre-install a Java version so it's ready to go the next time you start a server with this command. This differs from the normal package install command in that it doesn't install to the current working directory, but into the core server JRE folder that CommandBox manages for you. Use the --setDefault flag to also set the newly installed Java version as the global default for all servers.
server java install openjdk11 --setDefaultYou can remove a java installation so it doesn't take up space on your hard drive. Use the FULL ID that shows in the java list command to uninstall.
server java uninstall openjdk9_jre_x64_windows_hotspot_jdk-9.0.4+11Note, the download will still be in your artifacts cache. Also, if you start a server up again that asks for a Java installation you've uninstalled, CommandBox will simply re-install it again.