I have a Magento2 application running in a separate Ec2 instance behind Apache2. I have frontend instance running Nginx (in a different Ec2 instance too).
The frontend instance runs React.js (which renders the UI) and Nginx which acts as a proxy to both React and the Magento2 instance.
The Nginx configuration has been set as such that any normal requests go to the React code and any requests with /Magento/ in it are proxied to the backend instance running Apache2 and Magento.
I’ve got everything working except that when I try to access the Magento admin panel using the URL http://{hostname}/magento/index.php/admin (The admin URL in magento2 is set to hostname/magento/), I either get a 404 or an endless redirect of requests which ultimately fails. My current Nginx configuration is:
server {
server_name <hostname>; client_max_body_size 100M;
listen 80;
location / {
proxy_pass http://localhost:3000;
# Simple requests
if ($request_method ~* "(GET|POST)") {
add_header "Access-Control-Allow-Origin" *;
}
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
} location /magento/ {
proxy_pass http://<private IP address of the instance>/;
proxy_set_header Host $host;
}
}
I know something is wrong with my Nginx config because when I proxy everything to the backend (The admin URL in magento2 is set to hostname) as follows, the admin panel loads fine.
server {
server_name <hostname>; client_max_body_size 100M;
listen 80;
location / {
proxy_pass http://<private ip of the backend>;
# Simple requests
if ($request_method ~* "(GET|POST)") {
add_header "Access-Control-Allow-Origin" *;
}
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}}
Something is just off with Nginx that I am unable to catch. I did come across these links: https://github.com/magento/magento2/issues/1698 https://community.magento.com/t5/Magento-2-x-Hosting-Performance/Configuration-problems-with-Nginx-a... but I’m how to implement the same in my case if that is indeed the problem.
Can someone help me here? I’ve spent quite some time trying different variation in Nginx without any luck.
I have the same problem (but with Apache as proxy). @Scrumwheel did you ever figure it out? Or anyone else have a solution.
@ScrumwheelI'm using Apache so I can't test if this is the problem with nginx, but part of my problem was using "localhost", it should be "127.0.0.1". No idea why that matters but it does for me; give it a try.