GithubHelp home page GithubHelp logo

sumonst21 / server-configs-apache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from h5bp/server-configs-apache

0.0 2.0 0.0 1.05 MB

Apache HTTP server boilerplate configs

License: MIT License

Shell 100.00%

server-configs-apache's Introduction

Build Status

Apache Server Configs is a collection of configuration snippets that can help your server improve the web site's performance and security, while also ensuring that resources are served with the correct content-type and are accessible, if needed, even cross-domain.

Getting Started

There are a few options for getting the Apache server configs:

  • Download the zip archive
  • Install them via npm: npm install --save-dev apache-server-configs

Inside the dist/ folder, you'll find a ready-to-use .htaccess file.

Usage

If you have access to the main server configuration file (usually called httpd.conf), you should add the logic from the pre-built dist/.htaccess file in, for example, a <Directory> section in the main configuration file. This is usually the recommended way, as using .htaccess files slows down Apache!

If you don't have access, which is quite common with hosting services, just copy the .htaccess file in the root of the website.

Also note that some configurations won't have any effect if the appropriate modules aren't enabled. So, in order for everything to work as intended, you need to ensure the you have the following Apache modules enabled:

For more detailed information on configuration files and how to use them, please check the appropriate Apache documentation:

Enable Apache httpd modules

Standalone

These instructions should work on any distribution where apt-get has been used to install Apache.

  1. Open up a terminal and type the following command. Enter your password when prompted.

    sudo a2enmod setenvif headers deflate filter expires rewrite include

  2. Restart apache by using the following command so the new configuration takes effect.

    sudo /etc/init.d/apache2 restart

With MAMP/WAMP/XAMPP

  • MAMP PRO. On the main screen, click the Apache tab and ensure that all the required modules are 'checked', indicating they are enabled.

  • WampServer. If you have installed WampServer just click on the icon in the task bar then Apache section then modules section. You will be presented with a list of modules. Simply click on a module name to enable it. WampServer will automatically restart the Apache service after you enable a module.

  • Others. Locate the httpd.conf file, which is typically found in:

    • MAMP: /Applications/MAMP/conf/apache/httpd.conf
    • XAMPP: /Applications/XAMPP/etc/httpd.conf
    • WAMP: C:\apache\conf\httpd.conf

    Open the file in a text editor and uncomment all of the required modules. Once you have done so, reset MAMP/WAMP/XAMPP.

Custom .htaccess builds

Security, mime-type, and caching best practices evolve, and so should do your .htaccess file. In the past, with each new Apache Server Configs release it was quite tedious to find out which .htaccess trick was just new or only had changes in certain nuances.

The build script with its re-usable and customizable build configuration lets you easily update your .htaccess file. Each new .htaccess build will contain the updated Apache Server Configs source files, enabled or commented-out according to your settings in the htaccess.conf of your project root.

Configuration file: htaccess.conf

Allows you to define which module to enable or disable for your project. Just copy the default htaccess.conf from this repo into your project directory. Adjust to your needs, and/or add custom code snippets you need for your project. Its syntax is straight and pretty much self-explanatory:

# Example Module

title   "example module"
enable  "src/example-module/images.conf"
enable  "src/example-module/web_fonts.conf"
disable "src/example-module/not-needed.conf"
omit    "src/example-module/not-needed-at-all.conf"

... more modules ...

Disabling modules

For example, the “Cross-origin web fonts” snippet is always included in our pre-built .htaccess file and enabled. If your project does not deal with web fonts, you can disable or omit this section:

This will comment out the section:

disable  "src/cross-origin/web_fonts.conf"

…and this will exclude the section, saving lines in output:

omit  "src/cross-origin/web_fonts.conf"

Enabling modules

For example, the “Forcing https://” snippet is disabled by default, although being included in our pre-built .htaccess. To enable this snippet, change the disable keyword to enable:

enable "src/rewrites/rewrite_http_to_https.conf"

Adding custom modules

Imagine you're passing all requests to non-existing files to your favourite web framework. The according mod_dir snippet would go like this:

FallbackResource index.php

Store this snippet in a file, e.g. config/framework_rewrites.conf, and add a reference in your htaccess.conf:

# PROJECT MODULES
enable "config/framework_rewrites.conf"

Build script: build.sh

Dive into your project root and call the build script from wherever you cloned the repo. Here are three examples:

1. Create a default .htaccess
in current work directory. An existing htaccess.conf in this directory will be used; if none is present, the default configuration will apply.

$ path/to/server-configs-apache/bin/build.sh

# Output looks like:
[✔] Build .htaccess
[✔] Moved in place: './.htaccess'

2. Custom output location
Just add output path and filename as parameter. By the way, if there's an existing .htaccess file, the build script will create a backup.

$ path/to/server-configs-apache/bin/build.sh htdocs/.htaccess
[✔] Build .htaccess
[✔] Create backup: 'htdocs/.htaccess~'
[✔] Moved in place: 'htdocs/.htaccess'

3. Custom .htaccess configuration
Why not maintain your personal ~/htaccess.conf? This example creates a .htaccess in current work directory, according to your favourite settings you may have stored in your $HOME directory:

$ path/to/server-configs-apache/bin/build.sh ./.htaccess ~/htaccess.conf

Support

  • Apache v2.4.0+

  • Browsers:

    • Chrome
    • Firefox 4+
    • Internet Explorer 8+
    • Opera 12+
    • Safari 5+

Contributing

Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the guidelines:

Acknowledgements

Apache Server Configs is only possible thanks to all the awesome contributors!

License

The code is available under the MIT license.

server-configs-apache's People

Contributors

ad7six avatar adeelejaz avatar alrra avatar beverloo avatar chuanxshi avatar clarkni5 avatar drublic avatar h5bp-bot avatar hatzopoulos avatar heff avatar jingman avatar laukstein avatar leocolomb avatar malvoz avatar mathiasbynens avatar mattbrundage avatar midzer avatar mikealmond avatar mikewest avatar necolas avatar nilpo avatar paulirish avatar philwareham avatar phize avatar richardcornish avatar rmsr avatar sanand0 avatar westhouseit avatar wraithkenny avatar xhmikosr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.