I have X applications running on your servers and domains.
Separately they work fine.
To improve access, I want to use one alias for all applications instead of an alias for each application.
For example:
App1: http://app1.server.com
App2: http://app2.server.com
AppN: http://appN.server.com
In this way I want to make a proxy with NGINX to access applications like this:
App1: http://www.home.com/app1
App2: http://www.home.com/app2
AppN: http://www.home.com/appN
To do this a im using this configuration:
location ~/app1(.*)$ {
include /config/nginx/proxy.conf;
resolver 127.0.0.11 valid=20s;
proxy_pass http://app1.server.com$1$is_args$args;
}
location ~/app2(.*)$ {
include /config/nginx/proxy.conf;
resolver 127.0.0.11 valid=30s;
proxy_pass http://app2.server.com$1$is_args$args;
}
location ~/appN(.*)$ {
include /config/nginx/proxy.conf;
resolver 127.0.0.11 valid=30s;
proxy_pass http://appN.server.com$1$is_args$args;
}
But when a access the address, they return 404 or the page broke the img, css, because they need run in a root address.
Someone knows how to do it?
Related
Basically we have a set of microservices we have deployed to a kubernetes cluster hosted in AWS. We would like to run these through a gateway configuration in nginx.
Our current configuration which doesn't work looks something like this-
upstream some-api1 {
server some-api1:80;
}
upstream some-api2 {
server some-api2:80;
}
upstream some-api3 {
server some-api3:80;
}
server {
listen 80;
server_name gateway.something.com;
location /api1 {
proxy_pass http://some-api1;
}
location /api2 {
proxy_pass http://some-api2;
}
location /api3 {
proxy_pass http://some-api3;
}
}
Our services have been built with dotnet core, so the underlying urls would be something like http://some-api1/{api/controllername} . I'm always getting a 404 when I try hitting these endpoints through postman, which tells me it can't resolve these mappings.
However I'm able to access an api within the cluster using an explicit config for an api like so(which is what I don't want to do)-
server {
listen 80;
server_name someapi1.something.com;
location /{
proxy_pass http://some-api1;
}
}..
If someone could shed some light on what's wrong with the configuration or recommend the best approach for this it would be greatly appreciated.
As #Luminance suggests, you're seeing traffic to /api1 go to some-api1/api1 instead of just some-api1 on the base path for that target service (which is what your app would respond to). Following https://gist.github.com/soheilhy/8b94347ff8336d971ad0 you could re-write that target like
location /api1 {
rewrite ^/api1(.*) /$1 break;
proxy_pass http://some-api1;
}
The are two web applications (websites) written on Go. One is turalasgar.pro (here I am using Go built-in server). Another is engossip.com (for now it displays the same ip as former). I have a vps. I know I should use Nginx, but have no idea how? I have heard of Caddy. Please, I need only nginx server, not Caddy. What I need is run two (or more) applications by using my same vps. How should I configure Nginx configuration? Whether by listening to different ports or to the same port. Practical advices and examples highly appreciated.
It's called reverse proxy. Each application uses it's own port to listen. And then you just point to them in nginx config:
server {
listen 80;
server_name turalasgar.pro;
location / {
proxy_pass http://localhost:8080;
...
}
}
server {
listen 80;
server_name engossip.com;
location / {
proxy_pass http://localhost:8081;
...
}
}
Well is really easy.
follow this guide:
https://www.digitalocean.com/community/tutorials/how-to-use-martini-to-serve-go-applications-behind-an-nginx-server-on-ubuntu
After you achieved one application working with martini+nginx just add another server block for the other app.
In case you need more information about server blocks:
https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts
Above solutions I tried but didn't work for me
https://gist.github.com/soheilhy/8b94347ff8336d971ad0
server {
listen ...;
...
location / {
proxy_pass http://127.0.0.1:8080;
}
location /blog {
rewrite ^/blog(.*) /$1 break;
proxy_pass http://127.0.0.1:8181;
}
location /mail {
rewrite ^/mail(.*) /$1 break;
proxy_pass http://127.0.0.1:8282;
}
...
}
Usually, when doing a reverse proxy setup, you have a server on your backend which looks like this:
http://localhost:8084/app-root
and you can proxy_pass
location /app-root {
proxy_pass http://localhost:8084;
}
It will proxy www.my-domain.com/app-root to the internal server http://localhost:8084/app-root.
Great!
Can someone explain what needs to be done if the server insists on hosting from the root as so:
http://localhost:8084/index.html
http://localhost:8084/images/image1.jpg
I want this to be accessible via
http://www.my-domain.com/app/index.html
http://www.my-domain.com/app/images/image1.jpg
You can use rewrite of nginx. Something like this should work
location /app/ {
rewrite /app/(.*) /$1 break;
proxy_pass http://localhost:8084;
}
I'm new to nginx. I have two projects, and the one is django web app which is running localhost 8000, and another is tornado which used to provide api service and running localhost 8888.
How do I config the nginx that redirects all the url requests(from 80 port) to localhost:8000 but /api requests to localhost:8888(tornado app)?
Edit your nginx config file. Add a server block and use proxy_pass in location blocks to proxy (redirect) the request.
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:8000;
}
location /api {
proxy_pass http://127.0.0.1:8888;
}
}
Save it, and reload nginx.
nginx -s reload
https://gist.github.com/soheilhy/8b94347ff8336d971ad0
Having trouble figuring this out.
I have nginx running on home.domain.com.
Within my home network, I have multiple web services that I'd like to access externally through a reverse proxy. No SSL for now, but I'll add that later. I need to set up a reverse proxy on subdirectories of home.domain.com/app{1-3} as I only have a valid cert for home.domain.com.
My current configuration:
server {
listen 80 default;
keepalive_timeout 120;
server_name home.domain.com;
location /app1/ {
proxy_pass http://internalIP1:8081/;
}
location /app2/ {
proxy_pass http://internalIP2:5000/;
}
}
When I try to access home.domain.com/app1, it should redirect to home.domain.com/app1/login/?next=%2F, but instead goes to home.domain.com/login/?next=%2F. This obviously throws a 404, as it's not available on the nginx server.
Thoughts? Suggestions?