I am deploying my Laravel application to AWS ElasticBeanstalk. I have deployed it. Now, I am trying to override "/etc/nginx/conf.d/elasticbeanstalk/php.conf" file using .platform folder.
I created .platform/etc/nginx/conf.d/elasticbeanstalk/php.conf file right inside the project's root folder. Then I put in the configuration content.
Then I deploy my application executing "be deploy" command. But the Nginx config file is not overridden. What is wrong with my config and how can I get it working?
I tried using .ebextensions too creating a config file with the following content. The file is not just created.
files:
/etc/nginx/conf.d/elasticbeanstalk/laravel.conf:
mode: "000755"
owner: root
group: root
content: |
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
The nginx config file you are trying to set is used in Amazon Linux 1 (AL1).
For AL2, the nginx config files should be provided (aws docs) using:
.platform/nginx/conf.d/
or if you want to overwrite main nginx config file, use
.platform/nginx/nginx.conf
Thus, you can try the following file .platform/nginx/conf.d/laravel.conf with content of:
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
If it does not work, you can inspect nginx logs in /var/log or nginx config folder to check if the file is correctly placed in nginx config folder.
Solution I used
I used this and it worked.
.platform/nginx/conf.d/elasticbeanstalk/laravel.conf
Related
Hi I am using AWS elastic beanstalk for my Laravel application
When I first uploaded my application it is not showing the login page, 404 error so I tried with app_url/index.php/login and it worked
This is how I figure out I need to add this to my Nginx configuration, I manually added this, ssh into ec2 instance, and worked
location / {
try_files $uri $uri/ /index.php?$query_string;
}
but every time I deploy my new code it replaces my manual code
I also read https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-tomcat-proxy.html?icmpid=docs_elasticbeanstalk_console this doc and created this folder structure in my application root folder
.ebextensions
nginx
conf.d
elasticbeanstalk
my-server-conf.conf
Seems not working for me
Please let me know what should I put In my-server-conf.conf file and what should I do so it works for every deploy
You should be using .platform, not .ebextensions as explained in aws docs. For example:
.platform/nginx/conf.d/elasticbeanstalk/laravel.conf
location / {
try_files $uri $uri/ /index.php?$query_string;
}
I am using the in-built HTTP basic access authentication for Laravel Forge.
I am currently using basic_auth for all routes.
I would like to exclude one route (basic_auth off).
I tried to customise the file, example: /etc/nginx/forge-conf/.../server/.htpasswd-{ruleId}
I added the following additional code:
location = /example {
basic_auth off;
}
I also tried:
location /example {
basic_auth off;
}
I restarted nginx. I restarted the server. Same result: no change. The route /example was not excluded from basic_auth.
I was unable to find a solution using the in-built "Security" tool for basic authentication provided by Laravel Forge.
I was able to solve the problem by updating the nginx file for the site without using the aforementioned "Security" tool.
Replace www.example.com with your site address on Laravel Forge.
Replace /example with the path that you would like to exclude.
location / {
auth_basic "Restricted Access";
auth_basic_user_file /home/forge/www.example.com/.htpasswd;
try_files $uri $uri/ /index.php?$query_string;
}
location /example {
auth_basic off;
try_files $uri $uri/ /index.php?$query_string;
}
I created a .htpasswd file (search Google to find out how to generate your own with a username and password). I uploaded it to the root of my project directory, at the same level as the .env file.
I am migrating to Elastic Beanstalk and was not able to make changes to the nginx file, or even increment a new file. All configurations per AWS documentation did not work. So I did it as follows:
/.ebextesions -> 01_laravel_nginx.config:
files:
"/opt/elasticbeanstalk/support/conf/laravel.conf":
mode: "000644"
owner: root
group: root
content: |
location / {
try_files $ uri $ uri / /index.php?$query_string;
gzip_static on;
}
/.ebextesions -> 02_install_nginx.config:
container_commands:
01_runmyshellscript:
command: "sudo ln -s /opt/elasticbeanstalk/support/conf/laravel.conf /var/proxy/staging/nginx/conf.d/elasticbeanstalk"
After performing this configuration, the same information as in the /var/proxy/staging/nginx/conf.d/elasticbeanstalk directory will be in the /etc/nginx/conf.d/elasticbeanstalk directory.
Is there any better way?
I was just trying to add one more conf, instead of changing what already existed by default. I tried to perform this configuration as follows:
.platform / nginx / conf.d / laraval.conf
But I didn't create. have to create all the files?
.platform / nginx / conf.d / laraval.conf
.platform / nginx / nginx.conf
The proper way to setup nginx on EB environments using Amazon Linux 2 (AL2) is through .platform/nginx/conf.d/ as shown in the docs. Or if you want to fully overwrite the main nginx.conf you should provide its custom version using .platform/nginx/nginx.conf.
I'm trying to install magento php ecommerce on a virtual server that previously did not have php. When I put simple php pages into a directory they run (for example I have index.php run phpinfo). But when I try to run the magento setup scripts they bomb out without outputting an error. I have two other virtual servers through a different service (running apache) and when I drop the magento files into them the setup pages light up right away and start checking requirements. On my nginx server the only output is a small grey box, but no error output.
My best guess is that I have not configured nginx virtual hosts properly for php.
I am on php5.5 using fpm on Ubuntu 12.04. I don't run a default file in sites-enabled, just two vhost files. Here's the vhost in question (the other site is working fine, but it's python):
server {
listen 80;
listen [::]:80;
#
server_name magento.mydomain.com;
#
root /var/www/magento.mydomain.com/public_html;
index index.php index.html index.htm;
#
# location / {
# try_files $uri $uri/ /index.php =404;
# }
# location / {
# /index.php;
# }
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:8070;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/magento.mydomain.com/public_html/$fastcgi_script_name;
}
}
You can see my commented out location / directives. I have tried those is various fashion. My hunch was that magento was calling php with directory names only (instead of somedir/index.php) so I was messing with those, but it seems like that would be handled by the index directive before the locations.
I'm pretty green with nginx. Does anyone see anything obvious?
I merely followed the default Laravel Homestead setup here using VirtualBox. Working great.
But I need an additional Nginx rewrite setting in my apps vhost file on the VM, something like;
location / {
if ($request_method !~ "(POST)"){
rewrite ....
}
try_files $uri $uri/ /index.php?$query_string;
}
I can add that manually to the vhost file on the VM, but it's removed every time I provision my box.
How do I make that setting automatically applied when provision my vagrant VM box.
Is there a after provision hook, so I can run a script, or is there another easy solution available?
Easiest way to achieve this is editing scripts/serve.sh file, which contains server block template in block variable.