Skip to content
Closed
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e971c0a
Create README.md
Nov 30, 2015
30a4e2f
Create nginx.conf
Nov 30, 2015
c4a2b98
Create fastcgi_params
Nov 30, 2015
c1ebb82
Create assets.conf
Nov 30, 2015
64674a2
Create error_page.conf
Nov 30, 2015
c7c29b0
Create extra_protect.conf
Nov 30, 2015
0f11f35
Create hhvm.conf
Nov 30, 2015
87eb6a6
Create maintenance.conf
Nov 30, 2015
b5f306d
Create multishop.conf
Nov 30, 2015
0e13512
Create pagespeed.conf
Nov 30, 2015
537608c
Create php_backend.conf
Nov 30, 2015
1ac8ce5
Create setup.conf
Nov 30, 2015
b647dcd
Create spider.conf
Nov 30, 2015
8b27568
Create status.conf
Nov 30, 2015
8813cbd
Create default.conf
Nov 30, 2015
df90f56
Create magento2.conf
Nov 30, 2015
b161e63
Create port.conf
Nov 30, 2015
f27331e
Create README.md
Nov 30, 2015
86c0e6c
Update README.md
Nov 30, 2015
0b9ad0d
Update extra_protect.conf
Nov 30, 2015
8b193dc
config cleanup
Dec 3, 2015
04255a8
simplify assets management
Dec 4, 2015
f104572
simplify assets management
Dec 4, 2015
da9e58c
simplify assets management
Dec 4, 2015
111cd25
simplify assets management
Dec 4, 2015
01ed236
gzip and mime types update
Dec 5, 2015
c1e017c
Update spider.conf
Dec 5, 2015
9c27c45
gzip and mime types update
Dec 6, 2015
6506880
ssl_ciphers compatibility with payment gateways
Dec 10, 2015
4c95b64
Update nginx.conf
Dec 15, 2015
1bc1cca
Update nginx.conf
Dec 15, 2015
829fcba
Update hhvm.conf
Dec 15, 2015
0066abe
Update README.md
magenx Dec 18, 2015
59121f8
Update README.md
magenx Dec 18, 2015
1215680
Update README.md
magenx Dec 18, 2015
9afa16b
Update spider.conf
magenx Jan 30, 2016
280bca0
Update nginx.conf
magenx Feb 21, 2016
ce0d37e
Update magento2.conf
magenx Mar 18, 2016
6dd4d0a
Update magento2.conf
magenx Mar 28, 2016
9a40a83
Update php_backend.conf
magenx Apr 19, 2016
b26a184
Update magento2.conf
magenx Apr 19, 2016
65c92c6
Update magento2.conf
magenx Apr 19, 2016
b944a4b
Delete port.conf
magenx Apr 19, 2016
a7eb816
Update extra_protect.conf
magenx Apr 19, 2016
ff9275d
Update nginx.conf
magenx Apr 21, 2016
c2b322f
Update nginx.conf
magenx Apr 21, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions nginx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
TESTING<br/>
you have to install latest nginx package from official nginx repository<br/>
>http://nginx.org/en/linux_packages.html#mainline<br/>

to enable configuration you have to run these commands:<br/>
```cd /etc/nginx/sites-enabled/```<br/>
```ln -s /etc/nginx/sites-avalable/default.conf ./default.conf```<br/>
```ln -s /etc/nginx/sites-avalable/magento2.conf ./magento2.conf```<br/>
```nginx -t```<br/>
if no errors detected, then<br/>
```service nginx restart```

<br/>
for ssl configuration in nginx.conf you must: <br/>
1 - open ```cd /etc/ssl/certs``` <br/>
2 - generate dhparam file ```openssl dhparam -out dhparams.pem 2048``` <br/>
3 - enable in nginx.conf ```ssl_dhparam /etc/ssl/certs/dhparams.pem;``` <br/>

config:<br/>
```conf.d/assets.conf``` => settings for any static assets<br/>
```conf.d/error_page.conf``` => configure custom error pages<br/>
```conf.d/extra_protect.conf``` => protecting everything<br/>
```conf.d/hhvm.conf``` => hhvm vs php-fpm port/route mapping<br/>
```conf.d/maintenance.conf``` => global maintenance<br/>
```conf.d/multishop.conf``` => settings for multistore code<br/>
```conf.d/pagespeed.conf``` => pagespeed module settings<br/>
```conf.d/php_backend.conf``` => global settings for php execution<br/>
```conf.d/port.conf``` => configure http port<br/>
```conf.d/setup.conf``` => magento web setup/update (before web installation create dummy ```admin``` cookie as httponly)<br/>
```conf.d/spider.conf``` => bad user agents mapping<br/>
```conf.d/status.conf``` => nginx/php-fpm status locations<br/>

```www/default.conf``` => catch non-existent server name<br/>
```www/magento2.conf``` => magento virtual host/server configuration file<br/>

```fastcgi_params``` => global fastcgi parameters<br/>
```nginx.conf``` => main nginx configuration file<br/>
18 changes: 18 additions & 0 deletions nginx/conf.d/assets.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## images
location ~* /.*\.(jpg|jpeg|png|gif|svg|js|css|ico|txt)$ {
expires max;
log_not_found off;
access_log off;
add_header ETag "";
add_header Cache-Control "public";
}

## fonts
location ~* /.*\.(swf|eot|ttf|otf|woff|woff2)$ {
expires max;
log_not_found off;
access_log off;
add_header ETag "";
add_header Access-Control-Allow-Origin *;
add_header Cache-Control "public";
}
6 changes: 6 additions & 0 deletions nginx/conf.d/error_page.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# error_page 403 /403.html;
# location = /403.html {
# root /var/www/html/error_page;
# internal;
# access_log /var/log/nginx/403.log error403;
# }
34 changes: 34 additions & 0 deletions nginx/conf.d/extra_protect.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# deny all internal locations also default phpmyadmin
location ~ ^/(app|bin|var|nginx|phpserver|vendor|php[mM]y[aA]dmin|pma)/ { deny all; }

# deny access per default .htaccess rules
location ~ /media/(customer/|downloadable/|import/|theme_customization/.*\.xml) { deny all; }
location ~* /(media|static)/.*\.php$ { deny all; }
location ~ /errors/.*\.xml { deny all; }
location ~ Gruntfile\.js { deny all; }

## deny cron and files with the obvious names. favorite entry points for hackers and script kiddie
location ~* ^/(cron|phpminiadmin|pma|sqlyog|adminer.+)\.php { deny all; }

# deny auth and composer
location ~ (auth|package|composer)\.(json|lock)$ { deny all; }

# deny files that only for internal use (work with ssh or use ftp to download)
#location ~ /\. { return 444; } # <= block everythig that starts with \.<dot
location ~ /\.(svn|git|hg|htpasswd|bash|ssh|php_cs) { return 444; }
location ~ ^/.*\.(sh|pl|swp|phar|log|ini|sql|conf|yml|zip|tar|.+gz)$ { return 444; }

# limit requests and return GONE 410 for search bots (if you need something more - use firewall/iptables)
location ~ ^/(wishlist|customer|catalogsearch|newsletter|contact|sendfriend|catalog/product_compare|review/product/post|(fire|one.+)?checkout)/ {
limit_req zone=goeasy burst=5;
limit_req_status 429;
if ($http_user_agent ~* "Baiduspider|Googlebot|bingbot|rogerbot|Yahoo|YandexBot") { return 410; }
try_files $uri $uri/ /index.php?$args;
}

## Wordpress files and locations protection
location ~ /wp-config\.php { deny all; }
location ~ /wp-includes/(.*)\.php { deny all; }
location ~ /wp-admin/includes(.*)$ { deny all; }
location ~ /xmlrpc\.php { deny all; }
location ~ /wp-content/uploads/(.*)\.php(.?) { deny all; }
6 changes: 6 additions & 0 deletions nginx/conf.d/hhvm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Map HHVM and FPM ports
map $request_uri $port_switch {
default 9001; #HHVM
~^/(onestep|fire)?checkout/ 9000; #FPM
~^/(index\.php/)?admin/ 9000; #FPM
}
12 changes: 12 additions & 0 deletions nginx/conf.d/maintenance.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# if ($remote_addr !~ "^(1.2.3.4|1.2.3.4)$") {
# return 503;
# }

# error_page 503 @maintenance;

# location @maintenance {
# rewrite ^(.*)$ /error_page/503.html break;
# internal;
# access_log off;
# log_not_found off;
# }
15 changes: 15 additions & 0 deletions nginx/conf.d/multishop.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
map $http_host $MAGE_RUN_CODE {
hostnames;
.magento.com default;
.magento.de store_de;
.magento.fr store_fr;
promo.magento.com promo;
}

map $http_host $MAGE_RUN_TYPE {
hostnames;
.magento.com store;
.magento.de store;
.magento.fr store;
promo.magento.com website;
}
20 changes: 20 additions & 0 deletions nginx/conf.d/pagespeed.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pagespeed on;
pagespeed FileCachePath "/var/tmp/";
pagespeed LogDir "/var/log/pagespeed";

# to optimize images use: https://github.com/mikebrittain/Wesley
pagespeed EnableFilters convert_gif_to_png;
pagespeed EnableFilters insert_image_dimensions;
pagespeed EnableFilters lazyload_images;

pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters remove_comments;
pagespeed EnableFilters flatten_css_imports;

pagespeed EnableFilters insert_dns_prefetch;
pagespeed EnableFilters extend_cache;

pagespeed StatisticsLogging on;

pagespeed RetainComment "esi*";
pagespeed Disallow "*index.php/admin/*"
12 changes: 12 additions & 0 deletions nginx/conf.d/php_backend.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## php backend settings
fastcgi_pass 127.0.0.1:9000; #swap :9000 with :$port_switch when configuring hhvm/php-fpm routes;
fastcgi_index index.php;
include fastcgi_params;

## specific security and compatibility headers
add_header X-Frame-Options SAMEORIGIN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have control over this header in configuration

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe is better to send headers like these from the server not from the application. sending headers from application is good for debug or to report some errors with api ,.. etc

add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be disabled for IE8, where it can result in vulnerability with this header. It needs to be set to 0 for IE8

add_header X-UA-Compatible 'IE=Edge,chrome=1';
add_header X-Processing-Time $request_time;
#add_header Strict-Transport-Security "max-age=31556926; includeSubDomains; preload"; #<= uncomment if you run https only
11 changes: 11 additions & 0 deletions nginx/conf.d/setup.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
location ~ ^/(setup|update) {
root $MAGE_ROOT;
include /etc/nginx/conf.d/assets.conf;
location ~ ^/(setup|update)/index.php {
if ($cookie_admin = '') { return 404; }
include /etc/nginx/conf.d/php_backend.conf;
}
location ~ ^/(setup|update)/(?!pub/). {
deny all;
}
}
29 changes: 29 additions & 0 deletions nginx/conf.d/spider.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
map $http_user_agent $bad_client {
default 0;
~*(360Spider) 1;
~*(aiHitBot|AhrefsBot) 1;
~*(betaBot|BlackWidow|Bolt|BLEXBot|BUbiNG) 1;
~*(CazoodleBot|CPython|CCBot|ChinaClaw|Curious|CRAZYWEBCRAWLER|Custo) 1;
~*(Default|DIIbot|DISCo|discobot) 1;
~*(Exabot|eCatch|ecxi|EirGrabber|EmailCollector|EmailSiphon|EmailWolf|ExtractorPro|EyeNetIE) 1;
~*(FlashGet|Findxbot) 1;
~*(GetRight|GetWeb!|Go!Zilla|Go-Ahead-Got-It|Go.*package.*|GrabNet|Grafula|GT::WWW|GuzzleHttp) 1;
~*(heritrix|HaosouSpider|HMView|HTTP::Lite|HTTrack) 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this potentially can block some perl/python programs. Why do we need to response with 444 in this case? Also 444 have a special meaning " Used to indicate that the server has returned no information to the client and closed the connection." Why do you want to use this code? It does not look like correct behavior.

Copy link
Author

@magenx magenx Apr 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can block some perl/python programs.

which one?? when we tested this config few python and java clients where removed, others just a default noisy agents, it is good to keep them out. 444 will save you a lot of resources.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to include that in our distro? Sorry, its a custom decision which may (and will) affect search performance and i would never recommend to do this for the website without strict reason. Can we move all this crap out?

lol, if you need search bots to to hit and index all these url wishlist|customer|catalogsearch|newsletter|contact|sendfriend|catalog/product_compare|review/product/post|(fire|one.+)?checkout
go ahead remove it on your server/shop configuration...

~*(ia_archiver|IDBot|id-search|id-search.org|InterGET|InternetSeer.com|IRLbot) 1;
~*(JetCar) 1;
~*(larbin|LeechFTP|Lightspeedsystems|litemage_walker|Link|LinksManager.com_bot|Lipperhey|linkwalker|lwp-trivial) 1;
~*(Maxthon$|Mail.RU_Bot|MegaIndex.ru|MFC_Tear_Sample|microsoft.url|Microsoft-IIS|Microsoft|Mozilla.*Indy|Mozilla.*NEWT|MJ12bot|MSFrontPage) 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything from Microsoft?

~*(Navroad|NearSite|NetAnts|NetLyzer.*FastProbe|NetSpider|NetZIP|Nutch) 1;
~*(Octopus) 1;
~*(PageGrabber|panscient.com|pavuk|PECL::HTTP|PeoplePal|pcBrowser|PHPCrawl|PleaseCrawl|psbot|python-requests) 1;
~*(RealDownload|ReGet|RedesScrapy|Rippers|RocketCrawler) 1;
~*(SBIder|Scrapy|ScreenerBot|SEOprofiler|SeaMonkey$|SeznamBot|sitecheck.internetseer.com|SiteSnagger) 1;
~*(SmartDownload|Snoopy|SputnikBot|Steeler|SuperBot|SuperHTTP|Surfbot|sqlmap) 1;
~*(tAkeOut|Teleport|Toata|TwengaBot|Typhoeus) 1;
~*(URI::Fetch|User-Agent) 1;
~*(voltron|Vagabondo|VoidEYE) 1;
~*(webalta|WebAuto|[Ww]eb[Bb]andit|WebCollage|WebCopier|WebFetch|WebLeacher|WebReaper|WebSauger|WebStripper|WebWhacker|WhatsApp) 1;
~*(WebZIP|Wget|Widow|Wotbox|WWW-Mechanize|WWWOFFLE) 1;
~*(XSpider) 1;
~*(zermelo|Zeus|Zeus.*Webster|ZyBorg) 1;
}
13 changes: 13 additions & 0 deletions nginx/conf.d/status.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location ~ ^/(status|ping)$ {
include /etc/nginx/conf.d/php_backend.conf;
fastcgi_intercept_errors on;
access_log off;
allow 127.0.0.1;
deny all;
}
29 changes: 29 additions & 0 deletions nginx/fastcgi_params
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
#fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

# magento timeouts
fastcgi_connect_timeout 65;
fastcgi_send_timeout 7200;
fastcgi_read_timeout 7200;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 hours? really?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, 7200 sec = 2 hours ....
your htaccess file has php_value max_execution_time 18000

if you love to catch 504 timeouts , you can leave default settings which is 60s only...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hhvm - as i read from release note - it is compatible, do you have another magento 2 repo/version??

81 changes: 81 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
user nginx;
worker_processes auto;
worker_rlimit_nofile 100000;

pid /var/run/nginx.pid;

events {
worker_connections 2000;
multi_accept on;
use epoll;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is system (Linux) depended and should not be there

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, cpm can be selected automatically.

}

http {
index index.html index.php;
include /etc/nginx/mime.types;
types { application/font-woff2 woff2; }
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" ';
log_format error403 '$remote_addr - [$time_local] "$request"';

keepalive_timeout 5;
autoindex off;
server_tokens off;
port_in_redirect off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;

client_max_body_size 64m;
client_header_buffer_size 16k;
large_client_header_buffers 4 16k;

## Flood protection example (see conf.d/extra_protect.conf)
limit_req_zone $binary_remote_addr zone=goeasy:35m rate=1r/s;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks ajax autocomplete functionality

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update: just tested and it looks like working. no real damage.


## Cache open FD
open_file_cache max=10000 inactive=3600s;
open_file_cache_valid 7200s;
open_file_cache_min_uses 2;

## Gzipping is an easy way to reduce page weight
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_types application/javascript application/x-javascript application/rss+xml text/javascript text/css image/x-icon image/svg+xml;
gzip_buffers 16 8k;
gzip_comp_level 6;

## SSL global settings
#ssl_session_cache shared:SSL:45m;
#ssl_session_timeout 15m;
#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#ssl_ciphers "ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5";
#ssl_prefer_server_ciphers on;
#ssl_dhparam /etc/ssl/certs/dhparams.pem;

#ssl_stapling on;
#resolver 8.8.8.8 8.8.4.4 valid=3600s;
#resolver_timeout 5s;

## Use when Varnish in front
#set_real_ip_from 127.0.0.1;
#real_ip_header X-Forwarded-For;

## Multi shop code configuration
#include /etc/nginx/conf.d/multishop.conf;

## Map status to exclude from access log
map $status $writelog { 404 0; 410 0; 429 0; 444 0; default 1; }

## Map bad user agents
include /etc/nginx/conf.d/spider.conf;

## Map HHVM|php-fpm routes
#include /etc/nginx/conf.d/hhvm.conf;

## Main domain configuration
include /etc/nginx/sites-enabled/*.conf;

}
11 changes: 11 additions & 0 deletions nginx/sites-available/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
server {
include /etc/nginx/conf.d/port.conf;
return 444;
}

#server {
# listen 443 ssl default;
# ssl_certificate /etc/ssl/fake.crt;
# ssl_certificate_key /etc/ssl/fake.key;
# return 444;
#}
Loading