Currently, all requests under '/_webapi' are being forwarded to http://myproject.webapi/api with this configuration:
upstream web_api {
server myproject.webapi:80;
}
server {
location /_webapi {
proxy_pass http://web_api/api;
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;
}
}
Now, I want to remove the '/api' part. After I made some configuration from the web-api and use this configuration, it seems like it doesn't work:
server {
location /_webapi {
proxy_pass http://web_api;
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;
}
}
If directly accessed http://myproject.webapi/values and http://myproject.webapi/weatherforecast works fine. But when through Nginx reverse proxy using URL like http://localhost/_webapi/values or http://localhost/_webapi/weatherforecast, it doesn't work.
Related
How can i change url for site in Docker?
This conf work fine
location / {
proxy_pass http://127.0.0.1:3333;
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;
}
but with this conf not work
location /newurl/ {
proxy_pass http://127.0.0.1:3333;
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;
}
Take 404 not found for scripts,css files.
Can anybody tell me about configuration nginx, please?
Thanks
i think you need to replace the /newurl/ with command
location /newurl/ {
rewrite ^/newurl/(.*)$ /$1 break;
...
I'm trying to set up two node.js processes on 1 VPS with reverse NGINX proxy, with the following config I receive "CANNOT GET" error.
I've tried many different configs however I haven't gotten any to work with both processes...
upstream crypto {
server 127.0.0.1:3010;
}
upstream other {
server 127.0.0.1:3000;
}
server {
listen 443 http2 ssl;
ssl_certificate /etc/ssl/ssl-bundle.crt;
ssl_certificate_key /etc/ssl/private/nft-memes.io.key;
server_name nft-memes.io;
location /crypto {
proxy_pass http://crypto;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $proxy_protocol_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto tcp;
proxy_set_header X-NginX-Proxy true;
}
location /other {
proxy_pass http://other;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $proxy_protocol_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto tcp;
proxy_set_header X-NginX-Proxy true;
}
}
What am i doing wrong?
I want to redirect all requests starting with "mydomain/_dash" to "mydomain:8050/_dash" so that "mydomain/_dash-component-suites/" redirects to "mydomain:8050/_dash-component-suites/". I have added the following directive but it doesn't work. Plus, I also want to maintain the headers of each request.
location /_dash(.*)$ {
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-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
client_max_body_size 0;
proxy_pass http://analytics:8050/_dash(*);
}
You need to use regular expressions:
location ~ /_dash(.*)$ {
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-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
client_max_body_size 0;
proxy_pass http://analytics:8050/_dash$1;
}
I've configured nginx to forward HTTP to HTTPS. This works for everything except my reverse proxy websites (that are also configured in nginx). I am getting the error ERR_TOO_MANY_REDIRECTS in my web browser for reverse proxy sites. I'm not sure what I'm doing wrong.
Below, is the configuration I'm using in nginx.conf:
server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
location / {
root "C:\inetpub\wwwroot";
index index.html index.htm;
}
location /files {
proxy_pass http://localhost:89;
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;
}
location /photos {
proxy_pass http://localhost:89/photos/;
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 use nginx as a reverse proxy and I have one server as API and Websocket server. In order to use WebScoket I need to specify some headers:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
But, then I have some errors for API request and in order to fix it, I have to use:
proxy_set_header Connection keep-alive;
But, the line above breaks websocket connection. So, I can fix it by several locations:
location / {
proxy_pass http://0.0.0.0:5000;
proxy_http_version 1.1;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /someWebSocketUrl{
proxy_pass http://0.0.0.0:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /anotherWebSocketUrl{
proxy_pass http://0.0.0.0:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /oneMoreWebSocketUrl{
proxy_pass http://0.0.0.0:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
I don't like that I have to have separate location for every web socket url. Is it possible to simplify it? Something like:
location allWebSocketUrls_or_wss:// {
...
}
Just use for all statements:
location /websocketUrl {
...
}
For any location, which beginning as "/websocketUrl*". Or use regular expressions:
location ~ /(some|another|oneMore)?websocketUrl[1-3]*$ {
...
}
If you want exact urls. Or even simpler:
location ~ /.*websocketUrl.*$ {
...
}
which be used for any "websocketUrl". I think, it better to use special directory to all sockets, but this way will work too/
But if you have all same options, try to disable header:
location = / {
proxy_pass http://0.0.0.0:5000;
proxy_http_version 1.1;
proxy_set_header Connection keep-alive;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
proxy_pass http://0.0.0.0:5000;
proxy_http_version 1.1;
proxy_set_header Connection ""; # <--- this will disable header
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}