Laravel Forge - access app by naked IP instead of domain name - laravel

I have a laravel app on production (using Laravel Forge and a Digital Ocean droplet).
I'm able to access the app via www.domain.com, but if I try with the server's IP I get a 404 (nginx).
How can I manage to access the app with the IP address?
Thanks a lot for your help
EDIT:
Here is my Nginx config on Laravel Forge:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domain.com;
root /home/forge/domain.com/public;
...
}

This occurs because nginx searches for a configuration block containing default_server when no matching domain can be found. You can remove the default_server tag for the default(/etc/nginx/enabled-sites/default) and move it the config for the site you want to display by default:
server {
listen 80 default_server;
server_name example.net www.example.net;
...
}
your server block with updated default_server:
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2;
server_name domain.com;
root /home/forge/domain.com/public;
...
}
Be sure to edit the default config to remove the default_server tag before restarting nginx, it is not allowed to have two config blocks with default_server. The config can be verified using nginx -t
more information can be found at the nginx documentation

Why would you want to access your server from the naked ip?
Nginx returns a 404 since it cant find the requested domain on your server.
If you look at your folder structure your project folder corresponds to your site domain. It redirects you towards the right folder based on your domain name.
You could make a default project to show you something like phpinfo() when request trough the ip

Related

using nginx reverse proxy for docker container

I am using nginx on my ubuntu machine and setup 2 laravel application using docker and one wordpress website without docker
Application 1: localhost:8088
Application 2: localhost:8089
I wanted to achieve is that when someone open localhost so it opens wordpress website and if someone open localhost/app1 it opens application 1 and so on.
So I have created reverse proxy so that it can open my docker container application
This is what I have done
sudo nano /etc/nginx/sites-available/website
ln -s /etc/nginx/sites-available/website /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
After doing so when I try to open localhost/app1 it shows 404 but it recognise its a laravel app but shows 404
Here is my /etc/nginx/sites-available/website file code
server{
listen 80;
server_name localhost;
root /var/www/html/wordpress;
location /app1/{
proxy_pass http://localhost:8088;
}
}
You can create a file named redirects.map inside the nginx folder of your application and add a mapping like
~^localhost/app1/(.*) localhost:8089/$1;
You should change nginx configure from
server{
listen 80;
server_name localhost;
root /var/www/html/wordpress;
location /app1/{
proxy_pass http://localhost:8088;
}
}
To
server{
listen 80;
server_name localhost;
root /var/www/html/wordpress;
location /app1 {
proxy_pass http://localhost:8088;
}
}

SSL for local dmain

I have a project in Laravel. It was downloaded from a server to make some modifications. I have a SSL certificate for local domain (syworkx.local) from nginx. Can somebody help me with the installation and setting up the certificate
You can easily add an existing certificate to your nginx config file as shown below
listen 443 ssl;
server_name syworkx.local;
ssl_certificate /etc/nginx/ssl/syworkx_local.crt;
ssl_certificate_key /etc/nginx/ssl/syworkx_local.key;

Getting subdomains to work locally with Laravel

I am having a hard time getting subdomains to work locally. I have Docker serving the application to port 8080, and I am able to see the Laravel welcome screen. I then have a simple route setup like this:
Route::domain('{name}.localhost:8087')->group(function () {
return 'Hello World';acrylic dns
});
I am using Laravel's basic server, i.e. php artisan serve --host=0.0.0.0 --port=8087
When I try and view the page, nothing happens. It just goes to the welcome screen. I have even tried adding 'test.localhost' to the /etc/hosts file. Couple questions:
1) Can you have the port in the host like I have it there (in the Laravel route)?
2) I have seem somewhat similar posts where the solution was to use acrylic dns (on windows). I am using a Mac. Is this something where I need an actual DNS server?
3) I am planning on using nginx, do I need a 'beefier' web server to accomplish this?
With the basic Laravel server I have tried hard coding test.localhost in the route, with and without the port. I'm sure I am goofing something up, just not sure where. I am on a Mac, and I am running Laravel 5.6. Thanks in advance!
1) No, the web server configuration will listen on the port.
// nginx
server {
listen 8080;
...
}
2) You add the subdomains in your /etc/hosts file and create separate nginx configurations:
// /etc/hosts
subdomain1.foo.localhost 127.0.0.1
subdomain2.foo.localhost 127.0.0.1
subdomain3.foo.localhost 127.0.0.1
// nginx subdomain1.foo.localhost.conf
server {
listen 8080;
server_name subdomain1.foo.localhost;
...
}
// nginx subdomain2.foo.localhost.conf
server {
# set different port if needed
# listen 8082
listen 8080;
server_name subdomain2.foo.localhost;
...
}
// nginx subdomain3.foo.localhost.conf
server {
# set different port if needed
# listen 8083
listen 8080;
server_name subdomain3.foo.localhost;
...
}
3) Nginx is a production ready web server, you may need load balancers and multiple instances of the web servers to scale out, but nginx will be more than sufficient.
If you're using Artisan serve, go to
/etc/hosts (or similar)
127.0.0.1 subdomain.localhost
And open in the browser
subdomain.localhost:8087

#spinner{} element fails two worker when Nginx is the reverse proxy in front of Nitrogen

I have running my Nitrogen driven application directly however because i want to use Nginx load-balancing magic i found out that the progress notifier of Nitrogen, the Spinner is not showing at all. I followed the example as at Nitrogen configuration options - bottom of the page. The example code snippet at the link is shown below.
# My config for a site that I only want serving SSL content.
server {
listen 80;
server_name www.mysite.com, mysite.com;
access_log /var/log/nginx/mysite.com.access.log;
# rewrite all requests to be SSL
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 443;
server_name mysite.com www.mysite.com
access_log /var/log/nginx/mysite.ssl.access.log;
ssl on;
ssl_certificate ssl/mysite/mysite.com.crt;
ssl_certificate_key ssl/mysite/mysite.com.key;
ssl_client_certificate ssl/mysite/ca.crt;
location / {
# This installation is running on port 8021, as you can plainly see.
proxy_pass http://127.0.0.1:8000;
}
}
Without Nginx the spinner works fine. I am using Nitrogen over Yaws of release as stated in the RELEASE file [{release,"nitrogen","2.3.0-beta5","5.10.3",[...,...,...,...],permanent}]. I do not what I am not doing right.

nginx proxy from 80 to 444 same IP

I have some webs that are served by nginx with SSL (443) without problems.
Now, I have the web mail serving SSL on port 444, but I want nginx to proxy from 80 to 444 when webmail.mydomain.com reaches.
I've tried some config but no one of them worked. This is the last one ...
thanks,
m.
server {
listen 80;
server_name webmail.mydomain.com;
root /etc/nginx/sites-available/webmail/;
access_log /etc/nginx/sites-available/nginx.log;
client_max_body_size 50M;
location / {
proxy_pass http://192.168.1.2:444/;
proxy_redirect https://192.168.1.2:444;
}
}
I'm doing something similar. What worked for me was to define an upstream server on the same box
upstream some_name {
server 127.0.0.1:4000;
}
and then doing
proxy pass http://some_name;
Obviously my ports are different

Resources