Example -
mydomaine.com/back-end/api ---> its back-end
mydomaine.com ---> its front-end
I don't think many people understand this question. Because I don't understand how things will be. If anyone has trouble understanding my question - comment and tell me I will try to write better
anyone help plz..
You have to use a server block configuration of Nginx, try the following configuration:
server {
listen 80;
server_name mydomaine.com;
location /back-end/api {
# This would be the directory where your app static files are stored at
root /var/www/html/;
try_files $uri /index.html;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_redirect off;
proxy_pass http://mydomaine.com;
}
}
Related
I have a containerized dotnet service including swagger UI that I can locally run on localhost:7060/swagger/index.html.
I have a problem configuring nginx to point to it. Here is my weaplan.conf file that nginx detects
server {
Listen 80;
location /swagger {
root /var/www/html/weaplanservices/DataHandlerAPI;
proxy_pass http://127.0.0.1:7060;
try_files $uri $uri/ /index.html;
}
}
Note: the project exists in the exact indicated root and the containerized app works correctly
I solved this issue by reconfiguring nginx this way to serve Swagger UI:
server {
Listen 80;
location /swagger {
root /var/www/html/weaplanservices/DataHandlerAPI;
proxy_pass http://127.0.0.1:7060;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
I'm trying to pass multiple locations to a proxy, though, I can simply not make it work. Can anybody point me in the right direction?
This is what I have so far:
location / {
try_files $uri $uri/ /index.html =404
gzip on;
}
location ~* ^/(login|callback|ph|ch|th) {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_cache_bypass $http_upgrade;
proxy_pass http://127.0.0.1:4002;
}
As you probably can tell, I'm trying to pass
/login
/callback
/ph
/ch
/th
to localhost on port 4002, but it's not passing them?
EDIT: If it's of any help. I think my front-end it hijacking the path-location? Not sure though.
All requests are starts from /, so your location should look like this:
location ~* ^/(login|callback|ph|ch|th) {
if you use start string symbol.
I would like to have my drone installation running behind my nginx server. I want to access it under http://host/drone, but it doesn't seem to get the path option.
My nginx config looks like this:
server {
listen 80;
server_name myhost.io;
location ~ ^/drone/(.*)$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:8042/$1;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
And my configuration file like this:
DRONED_OPTS="--port=:8042 --path='/drone'"
Thanks for your help!
As Brad Rydzewski figured out, the --path option is only for the path to the sqlite database and drone can't be run in a subtree.
I have an odd issue which is only affecting one local app I'm working on - other apps with this approach seem to work fine (Ghost). This is from my Nginx server config:
location #node_proxy {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Host $host;
proxy_redirect off;
proxy_pass http://127.0.0.1:5000;
}
location / {
try_files #node_proxy =404;
}
As I said, I have Ghost running identically to this and it performs fine. However for this config it results in every request being a 404 - it seems to never hit the proxy. I've checked logs and this confirms my suspicions, no entries in the access or error logs.
The app I'm proxying through to in this instance is just a simple Express based node app, so nothing complex. Visiting http://127.0.0.1:5000 I see the expected results.
If I change my config to:
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Host $host;
proxy_redirect off;
proxy_pass http://127.0.0.1:5000;
}
It works as expected, however I'd like to make use of the named location so as to avoid having to repeat proxy declarations.
Have I missed something obvious?
Try this kind of hack:
location #root {
...
}
location / {
error_page 418 = #root; return 418; # redirect to #root
}
Seems like it is impossible to jump to named location from a regular one. You also can try try_files #root #root, however Igor Sysoev (nginx's author) says that error_page is better since it uses less resources.
I currently have two WORDPRESS websites sitting behind an NGINX proxy cache:
htxtp://local.example.com
htxtp://local.example.org
I want to access a URL from the first site but serve it from the second site whilst not losing the URL structure of the first (to allow website2.com to see the website1.com cookies).
For example:
I want:
htxtp://local.example.com/somepage/
To proxy the page built at:
htxtp://local.example.org/somepage/
BUT I don't want the URL to BE htxtp://local.website2.com.
My NGINX config is as follows:
server {
listen 80;
server_name local.example.com;
access_log logs/local.example.com.access.log;
error_log logs/local.example.com.error.log;
location /somepage {
proxy_pass http://localhost:8080;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host local.example.org;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
proxy_pass http://localhost:8080;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host local.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Any suggestions? I am trying to work out where the actual redirect is happening.