-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added production-grade nginx and Docker environment #1209
Conversation
ac093a3
to
83e29e0
Compare
83e29e0
to
d43c337
Compare
854d2cf
to
bb37180
Compare
Anyone else have any feedback or objections to making this the default? |
I did not find any noticeable differences in the use of Apache versus Nginx, but I must say that I had high-performance servers. I had an attempt to implement the Varnish cache and collaborated for a while on the Turpentine project, but the people interest waned. Although in the beginning I tried to implement Magento 1 with Nginx, HHVM, in the end I ended up leaving it with Apache because they came with version 2.4, PHP went to 7.0. Many users are familiar with Apache directives, .htaccess, .htpasswd and few panels install Nginx. The fact that you wanted to bring extra security to the project is to be appreciated but I would not default it immediately. I would create two versions of OpenMage, one classic to remain based on Apache and another for Nginx. Within the time limit I can help you testing this project even though I am not an Nginx fan :) |
Thanks for your feedback @addison74. The reason to favor nginx over Apache is the security of the configuration, I don't know that there is any appreciable performance benefit as Apache is quite fast. The intent is also just to provide a good model for out-of-the box hosting, not to remove support for Apache. Without such a model everyone does it their own way and some are probably very good and some probably very bad.. So not to say this is the best (though with help it could be) but the goal is to provide a very solid model for hosting OpenMage securely that is the "official" right way even if it isn't the only way. |
You are welcome. I remember when I did the first tests with Nginx I had to look for a lot of information resources to make Magento work with it. They didn't even exist much at that time. There were enough settings and I always had a piece of paper to find them when needed. Most people prefer Apache because once uploaded Magento starts out of the box without much efforts. As speed there is a winner LiteSpeed and Apache/Nginx on the same level. But with the new hardware resources throwing into play like NVMe the processing speed has improved radically. If it is up to me I would improve the content of the .htaccess file in Magento root. There are certain paths that should be blocked because they are periodically checked by bots. Also, when the webserver is behind a load balancer. In Apache case a directive in .htaccess saves you from installing modules. |
I agree, making Magento work on nginx can be a lot of work, that's why I want to make this easy for people by including it here.
That is my point exactly, rather than have to keep up with blocking dozens of paths the default should be that only the files that should be public are public and everything else is blocked. The safest way to guarantee this is to make each PHP file explicitly routed in nginx config so that you can't just drop PHP files in directories and execute them. I'm sure it's possible to do this in Apache somehow but it is much easier to do with nginx. The result is that you completely mitigate a lot of possible attacks or human errors by design. |
@colinmollenhour While I haven't tested your nginx config, I wanted to add a note on a small bug I just found running Magento behind nginx. In the admin section, go to a page like Manage Products, then hit Reset Filter, and try to use the pagination buttons. In my case, the pagination stopped working. Here's what happens. Before hitting Reset Filter the AJAX calls are like this:
After hitting Reset Filter, the AJAX calls are like this:
Notice the The simple solution is to add Hopefully this saves someone time, it lead me down a rabbit hole trying to figure out which commit in magento-lts broke this, which of course there was none. Edit: This can actually cause a security problem, as
|
In my opinion, DDEV is the fastest way for someone to get a test environment, regardless of whether the operating system is Windows or Linux. By editing the configuration file, you can set the Docker containers needed to run OpenMage. In the case of the webserver, you can choose for Nginx or Apache. I tested both of them and they worked immediately without any issues. I believe that Apache should remain as the default webserver version for OpenMage. For Nginx users, a tutorial should be created (e.g. Nginx.md) with all the necessary information and settings, some of them are in this PR. |
@addison74 The goal of this PR is not just for dev but also to provide a blueprint for a secure production environment. I like ddev as well, but I think a complex project like this should provide more out of the box in the way of server config since it is not easy for juinor admins and very easy to mess up even for senior admins. Currently we only provide "not ready for production!" environments so everyone is left to figure out production on their own. |
@addison74 I merged the latest main and the errors are resolved now.. |
I don't understand the question.. All files that are not in pub are inherently blocked with this configuration. |
Sorry, i remembered incorrectly that the root in "pub" was optional, but looking at the configurations, I realized I was mistaken. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love the idea of having more favicons (which, btw, I've replaced in this PR because there was one that too little and too complicated) and robots.txt, but this PR should be merged since it stayed waiting forever.
Not because it's awesome? 😉 |
heheheh it was awesome from the beginning ;-) |
boom, merged per 2gray+1green thanks @colinmollenhour! |
@colinmollenhour With Normal URL: www.example.com/admin Normal local.xml <admin>
<routers>
<adminhtml>
<args>
<frontName><![CDATA[admin]]></frontName>
</args>
</adminhtml>
</routers>
</admin> With [EDIT] I get it, this is where to set the admin URL: backend > System > Configuration > Admin: |
Yes, currently "Use Custom Admin Path" is not supported in this config - it would mostly work but there are a few nginx routes that need to be updated to support it. |
Trying to make use of nginx-admin.conf with URL like admin.example.com, which is set in backend > System > Configuration > Admin: [edit] magento-lts/app/code/core/Mage/Core/Controller/Varien/Front.php Lines 364 to 400 in 32ae767
Meaning, it's not possible to have a admin URL like admin.example.com, it needs the admin path: admin.example.com/admin |
Description
This pull request implements a far more secure web server configuration than the common Apache one. Apache is still fully supported but I would encourage the community to consider adopting this as a standard config long-term.
Why?
This nginx-based config naturally implements a much more secure design which is to allow only what is specified rather than allow all and then deny specific files. For example, right now the
LICENSE.txt
file is publicly accessible because we forgot to block access to it.In general the design here is to only load PHP through endpoints with the PHP file name hard-coded and only load static files outside of the pub subdirectories with the locations that are allowed.
Advantages:
index.php
,get.php
andapi.php
can be invoked from the web.htaccess
files that are scattered throughout. Many data leaks would be made impossible (e.g. I accidentally deletedvar/.htaccess
once.. oops!)Bonus 1: Multi-store automatic SSL
I added automatic-SSL support with easy multi-store configuration using Caddy. Basically you just create a new subdirectory of "pub" for each store code and edit the
Caddyfile
to map your domains to store codes and you're done!Bonus 2: Fine-grained rate limiting
The rate limiting is setup in nginx with separate zones for frontend, media, admin, api and post requests. Burst and delay are configured as appropriate. There is no rate limit set for static file requests but it could easily be added.
Fixed Issues (if relevant)
Manual testing scenarios (*)
Run
dev/openmage/install.sh
and test frontend and admin sites for common security flaws like exposed files/directories.Rate limiting can be tested with a tool like
hey
:Questions or comments
While this exact config has not been specifically battle-tested in production yet, it was derived from many years of production experience and is meant to be production-ready from a security standpoint.
Contribution checklist (*)