All Projects → nystudio107 → Nginx Craft

nystudio107 / Nginx Craft

Licence: mit
An Nginx virtual host configuration for Craft CMS that implements a number of best-practices.

Projects that are alternatives of or similar to Nginx Craft

Craftcms Docker
Craft3/Craft2 CMS Docker base (Nginx, PHP-FPM 8, PostgreSQL/MariaDB, Redis)
Stars: ✭ 99 (-64.13%)
Mutual labels:  craftcms, nginx
Slickstack
SlickStack is a free LEMP stack automation script written in Bash designed to enhance and simplify WordPress provisioning, performance, and security.
Stars: ✭ 311 (+12.68%)
Mutual labels:  craftcms, nginx
craft-plugin-mix
Helper plugin for Laravel Mix in Craft CMS templates
Stars: ✭ 50 (-81.88%)
Mutual labels:  craftcms
Nixy
nixy - nginx auto configuration and service discovery for Mesos/Marathon
Stars: ✭ 259 (-6.16%)
Mutual labels:  nginx
Craft-TemplateSelect
Allows you to select templates for an entry in Craft CMS
Stars: ✭ 30 (-89.13%)
Mutual labels:  craftcms
craft.doxter
Markdown editor and parser for Craft CMS
Stars: ✭ 80 (-71.01%)
Mutual labels:  craftcms
craft-commerce-widgets
Insightful widgets for Craft CMS Commerce stores
Stars: ✭ 33 (-88.04%)
Mutual labels:  craftcms
vue-asset
⛔️ DEPRECATED | Vue.js asset bundle for Craft 3 Beta
Stars: ✭ 23 (-91.67%)
Mutual labels:  craftcms
Nginx Resources
A collection of resources covering Nginx, Nginx + Lua, OpenResty and Tengine
Stars: ✭ 2,957 (+971.38%)
Mutual labels:  nginx
craft-entriessubset
Craft field type plugin that extends the core Entries field type to give extra settings
Stars: ✭ 27 (-90.22%)
Mutual labels:  craftcms
Yii2 Advanced One Domain Config
A template configuration without separation on the frontend and backend parts on different domains.
Stars: ✭ 258 (-6.52%)
Mutual labels:  nginx
craft-retour
Retour allows you to intelligently redirect legacy URLs, so that you don't lose SEO value when rebuilding & restructuring a website
Stars: ✭ 32 (-88.41%)
Mutual labels:  craftcms
transcoder
DEPRECATED Transcode videos to various formats, and provide thumbnails of the video
Stars: ✭ 24 (-91.3%)
Mutual labels:  craftcms
Webinoly
Optimized LEMP Web Server to manage your WordPress, PHP, or simple HTML sites running on a powerful NGINX setup.
Stars: ✭ 254 (-7.97%)
Mutual labels:  nginx
dospaces
DigitalOcean Spaces integration for Craft CMS
Stars: ✭ 31 (-88.77%)
Mutual labels:  craftcms
Lnmp
Support: Nginx 1.12/1.13 + MySQL 5.5/5.6/5.7/8.0(MariaDB 5.5/10.0/10.1/10.2/10.3) + PHP 5.4/5.5/5.6/7.0/7.1/7.2 + phpMyAdmin(Adminer)
Stars: ✭ 262 (-5.07%)
Mutual labels:  nginx
craft3-codemirror
Add the awesome in-browser code editor CodeMirror as a field type.
Stars: ✭ 17 (-93.84%)
Mutual labels:  craftcms
Craft-UserCreator
Allow you to generate users en masse, simply.
Stars: ✭ 16 (-94.2%)
Mutual labels:  craftcms
craft-recipe
A comprehensive recipe FieldType for Craft CMS that includes metric/imperial conversion, portion calculation, and JSON-LD microdata support
Stars: ✭ 23 (-91.67%)
Mutual labels:  craftcms
Open Proxy
一键部署被墙网站反向代理; 免翻墙访问被禁网站
Stars: ✭ 274 (-0.72%)
Mutual labels:  nginx

nginx-craft

An Nginx virtual host configuration for Craft CMS that implements a number of best-practices.

Overview

What it handles

The Nginx-Craft configuration handles:

  • Redirecting from HTTP to HTTPS
  • Canonical domain rewrites from www.SOMEDOMAIN.com to SOMEDOMAIN.com
  • 301 Redirect URLs with trailing /'s as per https://webmasters.googleblog.com/2010/04/to-slash-or-not-to-slash.html
  • Setting PATH_INFO properly via php-fpm -> PHP
  • Setting HTTP_HOST to mitigate HTTP_HOST Security Issues
  • "Far-future" Expires headers
  • Enable serving of static gzip files via gzip_static
  • Adding XSS and other security headers
  • Gzip compression
  • Filename-based cache busting for static resources
  • IPv4 and IPv6 support
  • http2 support
  • Reasonable SSL cipher suites and TLS protocols
  • Localized sites
  • Server-side includes
  • Optionally includes Dotenvy generated .env files

Assumptions made

The following are assumptions made in this configuration:

  • The site is https
  • The SSL certificate is from LetsEncrypt.com
  • The canonical domain is SOMEDOMAIN.com (no www.)
  • Nginx is version 1.9.5 or later (and thus supports http2)
  • Paths are standard Ubuntu, change as needed
  • You're using php7.1 via php-fpm
  • You have 'omitScriptNameInUrls' => true, in your craft/general.php

If any of these assumptions are invalid, make the appropriate changes.

Note: We disable TLSv1.0 because it is insecure, but IE 8, 9 & 10 need to have support for TLSv1.1 manually enabled or they will not be able to connect.

What's included

This Nginx configuration comes in two parts:

  • sites-available/somedomain.com.conf - an Nginx virtual host configuration file tailored for Craft CMS; it will require some minor customization for your domain
  • nginx-partials - some Nginx configuration partials used by all of the virtual hosts, logically segregated. These don't need to be changed, but can be selectively disabled by changing the suffix to .off (or anything other than .conf)

Using Nginx-Craft

  1. Obtain an SSL certificate for your domain via LetsEncrypt.com (or via other certificate authorities). LetsEncrypt.com is free, and it's automated. You will need a basic server up and running that responds to port 80 to do this, LetsEnecrypt/Nginx tutorial
  2. Create a dhparam.pem via sudo openssl dhparam -out /etc/nginx/dhparams.pem 2048
  3. Download your Issuer certificate via mkdir /etc/nginx/ssl; sudo wget -O /etc/nginx/ssl/lets-encrypt-x3-cross-signed.pem "https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem"
  4. Upload the entire nginx-partials folder to /etc/nginx/
  5. Rename the somedomain.com.conf file to yourdomain.com.conf
  6. Do a search & replace in yourdomain.com.conf to change SOMEDOMAIN -> yourdomain
  7. Tweak any paths that may need changing on your server
  8. Change the fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; line to reflect whatever version of PHP you're running
  9. Restart nginx via sudo nginx -s reload

If you're using Forge, it takes care of a number of these things for you, but still needs tuning.

The same applies for CloudWays, ServerPilot, Homestead, MAMP, etc.

A Forge Template is provided in forge-templates/NginxTemplate.conf that you can use to automate setting up your Forge servers.

For this to work, you must clone the repo into /home/forge via:

git clone https://github.com/nystudio107/nginx-craft.git /home/forge

For further information on TLS optimization, see the How to properly configure your nginx for TLS article.

Forge & opcache

N.B.: Forge now has opcache functionality baked-in, you can enable it via the Server settings, so this information is largely deprecated.

If you're using Forge, understand that opcache is off by default. To enable it, go to your server in Forge, click on Edit Files and choose Edit PHP FPM Configuration and search on opcache. Here are the defaults I use; tweak them to suit your needs:

[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
;opcache.enable_cli=0

; The OPcache shared memory storage size.
opcache.memory_consumption=256

; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=16

; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 100000 are allowed.
opcache.max_accelerated_files=8000

; If disabled, all PHPDoc comments are dropped from the code to reduce the
; size of the optimized code.
opcache.save_comments=0

More about tweaking opcache can be found in the Fine-Tune Your Opcache Configuration to Avoid Caching Suprises article. The Best Zend OpCache Settings/Tuning/Config article is very useful as well.

Local Development

While all of the configuration in the somedomain.com.conf will work fine in local development as well, some people might want a simpler setup for local development.

There is a basic_localdev.com.conf that you can use for a basic Nginx configuration that will work with Craft without any of the bells, whistles, or optimizations found in the somedomain.com.conf.

While this is suitable for getting up and running quickly for local development, do not use it in production. There are a number of performance optimizations missing from it.

Brought to you by nystudio107

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].