I'm having some issues hosting blazor WASM standalone (without an asp.net core project as host) behind nginx as a reverse proxy.
Here is my Nginx default config file:
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /var/www/web/BlazorApp/wwwroot;
try_files $uri $uri/ index.html =404;
include /etc/nginx/mime.types;
types {
application/wasm wasm;
}
default_type application/octet-stream;
}
location /service1/ {
proxy_pass http://localhost:5001/;
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 /service2/ {
proxy_pass http://localhost:5002/;
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 /service3/ {
proxy_pass http://localhost:5003/;
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;
}
}
This Configuration works in the sense that I can access my blazor app using
http://{server-ip-address}
and my other services using
http://{server-ip-address}/serviceX
where X would refer to service 1,2 and 3 respectively
First issue: when I navigate in my blazor app for example to http://{server-ip-address}/My-Blazor-Page and I refresh the page I get a 404 not found error.
for it to work back again I need to go back to the base address http://{server-ip-address} and navigate back to My-Blazor-Page.
I cannot refresh a page and go back to the same page.
Second issue: I would like my blazor app to have a different location. I would like to use http://{server-ip-address}/Blazor rather than http://{server-ip-address}/.
I tried everything to get it right but this is the only config that semi-works
Many thanks for your help!
The following nginx.conf file is simplified to show how to configure Nginx to send the index.html file whenever it can't find a corresponding file on disk.
When setting the NGINX burst rate limit with limit_req, Blazor WebAssembly apps may require a large burst parameter value to accommodate the relatively large number of requests made by an app. Initially, set the value to at least 60:
Increase the value if browser developer tools or a network traffic tool indicates that requests are receiving a 503 - Service Unavailable status code.
For more information on production Nginx web server configuration, see Creating NGINX Plus and NGINX Configuration Files.
The above will try the URL, and if no file matches, it'll serve index.html instead. This is the way.
For your second issue, you should set the base attribute value to "Blazor" and put all files in the Blazor directory (the config needs to match this). You can also route differently, but this is the easiest.
Related
I'm serving a website, generated by a docker container, using nginx, which also lives in a docker container. This setup works quite well.
What I want to do now, is serve multiple websites, from multiple containers.
My (simplified) setup is below.
http {
upstream app_01 {
server container_01:80;
}
upstream app_02 {
server container_02:80;
}
server {
listen 443 ssl;
include common.conf;
include /etc/nginx/ssl.conf;
location / {
proxy_pass http://app_01;
proxy_redirect off;
include common_location.conf;
}
location /alternative {
proxy_pass http://app_02;
proxy_redirect off;
include common_location.conf;
}
}
}
common_location.conf contains:
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 $host;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Port $server_port;
My original website still works fine (container_01), and I can kinda access the second site (container_02); the starting page gets loaded partially. It appears that it keeps the upload/ part in all links.
My question: how do I get this to work?
Since nobody seems to be able to answer, I ended up using an alternative to nginx, which worked within ten minutes.
Placed frontend and backend in nginx. I'm trying to correctly configure that after authorization, nginx redirected me to the original page.
Nginx Conf:
##Frontend
server_name atlas.com;
location / {
root /ops/front_2.0/dist/;
index index.html;
}
##Backend
location /api {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
With this configuration, the backend does not work, I will not get to the authorization page and a 404 Not Found error occurs.
But if, with the same settings, you place the Backend on another domain name, for example:
server_name server.atlas.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
}
Then everything works fine. But such a solution does not suit me, since it is not convenient to use for Frontend, since a CORS error is raised.
I'm neither familiar with nginx nor asp.net core. but i'm trying with both.
My nginx server is using default configurations, serving several very simple html pages on 80 port. Currently the homepage is: http://leiyang.icu or https://leiyang.icu.
One net5 built in asp.net core blazor sample app is hosted in a different location from nginx document root, and works well: http://leiyang.icu:8080/
The goal is redirecting:
$host/net --> $host:8080
$host/net/counter --> $host:8080/counter
$host/net/anything --> $host:8080/anything
and so on, while keeping the url in browser.
I've tried simple rewrite rule
rewrite /net(.*) http://leiyang.icu:8080/$1 permanent;
but it shows redirected url in browser, which is not expected.
I tried proxy_pass following Host ASP.NET Core on Linux with Nginx. now if user go to http://leiyang.icu/net/, he can see the page, but css is not loaded(screeshot attached).
location /net/ {
proxy_pass http://localhost:8080/;
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 guess possible reason is my proxy_pass configuration didn't specify different document roots.
But I cannot figure out how to solve. Could anyone give some suggestions?
I've just deployed a flask application with Gunicorn and Nginx. The application is running under 192.168.25.49 address. Nginx configured as following:
server {
listen 80;
server_name 192.168.25.49;
location / {
include proxy_params;
proxy_redirect off;
proxy_set_header host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-forward-for $proxy_add_x_forwarded_for;
proxy_pass http://unix:/home/avin/Saba/saba.sock;
}
}
The problem is: When I enter 192.168.25.49 in the address bar, it automatically changes to http://192.168.25.49,192.168.25.49/login. This problem occurs on login and logout too.
I've searched whole the internet but nothing found for this problem. If anyone with Nginx knowledge help me will appreciate.
I have a main server running NGINX and a second server running Apache/cPanel.
What we are trying to do is keep our micro sites seperate from the main server. The micro sites are mainly Wordpress
The issue that I am running into is that we want them to have the domain format of http://example.com/path.
However it has come to my attention that using the following proxy_pass below it does not work for more then one site.
It also has been recommended to me that the microsites get turned into subdomains on the second server to ease the proxy_pass confusion - path.example.com
I then run into the issue of how do I get http://example.com/path to mirror path.example.com and work like http://example.com/path
Currently it semi works by using the below however /private just loads /blog
Config:
location /blog/ {
include proxy-pass-settings.conf;
proxy_pass http://blogging.example.com/;
}
location /private/ {
include proxy-pass-settings.conf;
proxy_pass http://blogging.example.com/;
Proxy Config:
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
Try this:
location ^~ /blog/ {
include proxy-pass-settings.conf;
proxy_pass http://blogging.example.com;
}
location ^~ /private/ {
include proxy-pass-settings.conf;
proxy_pass http://blogging.example.com;
}
If proxy_pass is specified without a URI, the request URI is passed to the server in the same form as sent by a client when the original request is processed, or the full normalized request URI is passed when processing the changed UR.
Source: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass