Nginx forward requests to the new URL - http

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

Related

Nginx - Reverse proxy all requests starting with a keyword

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

Nginx Basic authentification for an upstream location

i am trying to get a basic authentification in an nginx conf for an upstream.
location /movies/ {
rewrite /movies/(.*)$ /$1 break;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_buffering off;
proxy_pass http://jd2movies;
auth_basic "Administrator Login";
auth_basic_user_file /root/.htpasswd;
}
but i get an "500 Internal Server Error"
How can i achieve this to get it working?
Thanks

Nginx location and reverse proxy configuration not working properly

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.

Deploy Udash demo app to NGINX

How can I deploy the Udash framework demo outside of SBT, and run it under NGINX?
I know it is lame, but I am able to run under NGINX with this line:
nohup sbt -Djline.terminal=jline.UnsupportedTerminal run &
and these location mappings:
location /notifications/ {
proxy_pass http://127.0.0.1:12345;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
location /atm/ {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /frontend/ {
proxy_pass http://127.0.0.1:12345;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
location / {
proxy_pass http://0.0.0.0:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}

Nginx proxy pass append request parameter to upstream

Here is my site conf -
upstream demo {
server server1:31337;
server server2:31338;
server server3:31339;
server server4:31340;
keepalive 64;
}
server {
listen 80;
server_name www.site.org;
rewrite ^ https://$server_name$request_uri? permanent;
location / {
proxy_redirect off;
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 Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_cache one;
proxy_cache_key sfs$request_uri$scheme;
proxy_pass http://demo;
}
}
I want when I open www.site.org it should proxy pass to any of the upstream server as server2:31337/mysite
How do I append /mysite request paramater ?
Can you try this
location / {
proxy_redirect off;
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 Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_cache one;
proxy_cache_key sfs$request_uri$scheme;
rewrite ^(.*)$ /mysite$1 break;
proxy_pass http://demo;
}

Resources