I'm setting up a new Amazon Linux 2/PHP/NGINX environment and I'm a little unfamiliar with Nginx since my last environment on Elastic Beanstalk was Amazon Linux/PHP/Apache. (Amazon changed the proxy to Nginx from Apache and the underlying platform was upgraded from Amazon linux to AL2)
Previously, I had an .htaccess file to handle multiple domains where a domain would have a corresponding folder that it would be served from. But, I know that .htaccess file won't work with Nginx.
So far I've tried adding a config file to the .ebextensions folder with something like this:
files:
"/etc/nginx/sites-available/example.com.conf":
mode: "000644"
owner: root
group: root
source: https://someothersite.com/example.com.conf
The source being referenced (example.com.conf) contains this:
server {
listen 80;
root /var/www/html/example.com;
index index.html index.php;
server_name example.com;
location / {
try_files $uri $uri/ =404;
}
}
I thought I needed to create a symbolic link, so I have another config file in the .ebextensions folder that contains this:
commands:
10_link:
command: sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
After this ln command, I get an error during build. If I don't do that command I don't get an error, but it doesn't work (example.com/test.php wouldn't be served)
My last attempt was to do nothing in the .ebextensions folder and I created .platform/nginx/conf.d/custom.conf with the contents of
server {
listen 80;
root /var/www/html/example.com;
index index.html index.php;
server_name example.com;
location / {
try_files $uri $uri/ =404;
}
}
This seems to be closer as example.com/test.php is going to the file, but the server is prompting the browser to download the php file instead.