How do you use basic_auth for all but one route using Laravel Forge - laravel

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.

Related

Nginx proxy return 404 with Laravel and Vue

i have a problem with nginx and laravel/vue app, hope yours help
I have two web app call Admin and System.
Admin use Vuejs call api to System using Nginx proxy (image bellow)
server {
listen 80;
server_name admin.abc.com;
location / {
root /usr/share/nginx/html/onestudy-vuejs/dist;
index index.html;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass https://system.abc.com;
}
location ~ /\.ht {
deny all;
}
}
After some day not access to web, i have error such as when access api from admin domain (example: https://admin.abc.com/api/user_info)
{"error":{"name":"Error","status":404,"message":"There is no method to handle ","statusCode":404}}
every request 3 times, 2 times ok and 1 time i see this error
but if access direct from system admin, everything will be still ok
After this, i just restart nginx, i don't see this error??? :( don't understand, don't know exactly what the cause is ##
Note: My project has two env, staging and prod, but only prod has error (same config nginx between two env)
Some info of project
Tech stack: Laravel, Vue
Webserver: Nginx
Cloud: AWS (EC2 + ALB)
I see this topic nginx proxy_pass 404 error, don't understand why but it's not for my problem
Glad for your support.
If u need info of system for anwser, please request bellow. Tks u

Custom nginx configuration for Laravel in AWS Elastic Beanstalk

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;
}

Laravel 4.2 on Nginx getting 404 (VPS)

I'm trying to use the Laravel 4.2 on nginx. I have a VPS (Dreamhost) and I put the Laravel framework inside the root path of user (/home/vi360/) and the public path is on /home/vi360/vide360.com.br
I've been researching several ways to set up nginx for Laravel, but I'm not getting any success. Only the home page is opening (www.vide360.com.br), but all the other pages (directed by /home/vi360/app/routes.php) are returning with error 404.
I have created the /home/vi360/nginx/vide360.com.br/vide360.conf as follows:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/vi360/vide360.com.br;
index index.php index.html index.htm;
server_name [server ip address];
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
What am I maybe doing wrong?
I guess you changed the public folder name.
Laravel looks up its files in public folder. Say your laravel application running on /home/vi360 then your public folder path will be /home/vi360/public.
Then on your nginx, it should be like
root /home/vi360/public;
Try renaming the vide360.com.br folder back to public and it will be fine. This is because the framework follows the request by booting up and forwarding it to public/index.php file.
Don't forget to restart nginx and php-fpm after the settings change.
EDIT
If the developer wants to change the public directory of laravel from public folder to other folder, say vide360.com.br, then edit your Application Service Provider (ASP) which is located at App\Providers\AppServiceProvider.php. And under the register method add the code with your new public folder name.
$this->app->bind('path.public', function() {
return base_path().'/vide360.com.br';
});

Laravel 5/ 5.4 paginator is not working in NGINX production environement

In my local environment i did $items = Model::paginate(10); and it worked. Then i pushed it to production and when i click on the pagination links it displays page 1 again and again. then i did dd($items). i found that the current Page property of length aware pagination is not changing when i change the address to /items?page=*. How to make current page property change accordingly or there is some thing else? thanks in advance
I am using ubuntu 16.04 nginx server. The problem was that $_GET session variables were not being set properly. so what I did was inside /etc/nginx/sites-available/default and inside location / block/ directive I changed try_files $uri $uri/ /index.php?$query_string; to try_files $uri $uri/ /index.php?$args; and it worked. Or see Laravel 5 - NGINX Server Config Issue with URL Query Strings
Awsome Thanks #Ahmed
I just had to change mine from
location / {
try_files $uri $uri/ /index.php?$query_string;
}
to
location / {
index index.php;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /index.php/$1 last;
}
as i saw some of my other sites was using the #rewriteapp part and seem to work fine.

Hosting Laravel Application on Ubuntu Server

I have recently developed my first Laravel application (version 5.2.).
I now want to host the application on my client's server running Ubuntu.
Their admin managed to install and run the native Laravel application on the server which works just fine, however when I come to copy and paste my own application over, the browser returns:
403 Forbidden
nginx/1.4.6 (Ubuntu)
Accessing the public folder directly (www.example.com/public/index.php) the browser returns:
The www.example.com page isn’t working
www.example.com is currently unable to handle this request.
HTTP ERROR 500
Can anybody please help me out with the proper method of hosting my application?
Seems more like an nginx-problem. Try to change your nginx virtualhost config to this.
server {
listen 80;
server_name yoursite.tld
root /var/www/yoursite/public/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
First save your file inside,
var/www/html/
Then using Terminal go to your folder
cd var/www/html/your_folder
Run Laravel application
sudo php -S localhost:8888 -t public
Make sure your port number is not same as the other Laravel instance running in the server.

Resources