using nginx reverse proxy for docker container - laravel

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

Related

Why is my nginx reverse proxy not working? (macos)

I installed nginx using brew install nginx
Screenshot of the terminal commands and their results
I started nginx using brew services start nginx
I changed the usr/local/etc/nginx/nginx.conf file to add a new location and i changed the user to mobi staff
I added
location /p1/ {
proxy_pass http://127.0.0.1:5000/api/product;
}
location /p2/ {
proxy_pass http://www.google.com;
}
Neither of the proxy pass things are working, i added the google.com one to test if it would work but when i go to localhost:8080/p1/ or localhost:8080/p2/ i get a 404 not found. How do I fix this so I can setup a reverse proxy that will go to those links?
Screen shot of the install and nginx.conf
I figured it out, I moved the
location /p1/ {
proxy_pass http://127.0.0.1:5000/api/product;
}
location /p2/ {
proxy_pass http://www.google.com;
}
code to be just below the server
server {
listen 8080;
server_name localhost;
location /p1/ {
proxy_pass http://127.0.0.1:5000/api/product;
}
location /p2/ {
proxy_pass http://www.google.com;
}
and then instead of running
sudo brew services restart nginx
I ran
brew services restart nginx
and it works i get redirected to the urls now!

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

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

#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.

How do I create multiple locations with Nginx, Passenger, Sinatra

I have a server section that looks like:
server {
listen 80;
server_name arch;
root /data/apps/production/fentonGem2/current/public;
passenger_enabled on;
}
which works fine. However, I'd like to deploy two or more apps to the same server_name and listen port. So presumably I'd use something like the following:
server {
listen 80;
server_name arch;
location /app1 {
root /data/apps/production/fentonGem2/current/public;
passenger_enabled on;
}
location /app2 {
root /data/apps/production/fentonGem3/current/public;
passenger_enabled on
}
}
But that doesn't work. Does anyone know how I can deploy two separate apps, and reach them by:
http://domain.com/app1/
and:
http://domain.com/app2/
The setup uses Nginx, Phusion Passenger, Rack, and Sinatra.
UPDATE:
Thanks for the responses, but I found them and the approach not helpful, though maybe I'm not understanding it well. It kind of seems like I have to deploy one application inside another, which seems very unclean. What I finally resorted to was having separate server sections, and then updating my /etc/hosts file to have server aliases for the same IP address. So now I have:
http://app1/
and:
http://app2/
and server sections that look like:
server {
listen 80;
server_name app1;
root /data/apps/production/app1/current/public;
passenger_enabled on;
}
server {
listen 80;
server_name app2;
root /data/apps/production/app2/current/public;
passenger_enabled on;
}
and in /etc/hosts:
192.168.1.30 app1 app2
The following worked:
First made symlinks named app1 and app2 pointing to the "public" directory as follows:
ln -s /data/apps/production/fentonGem2/current/public /data/apps/production/fentonGem2/current/app1
ln -s /data/apps/production/fentonGem2/current/public /data/apps/production/fentonGem2/current/app2
Modify nginx.conf to have rails_base_uri, which should look something like the following:
...
server {
listen 80;
server_name arch;
location ^~ /app1 {
root /data/apps/production/fentonGem2/current;
rails_env production;
passenger_enabled on;
passenger_base_uri /app1;
}
location ^~ /app2 {
root /data/apps/production/fentonGem2/current;
rails_env production;
passenger_enabled on;
passenger_base_uri /app2;
}
}
...
Hope this helps.
Not sure, but you might need passenger_base_uri /app1;
More about Passenger and Nginx conf:
http://www.modrails.com/documentation/Users%20guide%20Nginx.html#PassengerBaseURI
EDIT:
"It is allowed to specify this option multiple times. Do this to deploy multiple applications in different sub-URIs under the same virtual host."

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