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;
}
}
Related
I am installing grandnode on ubuntu server. I installed nginx and configured it as a reverse proxy. In the sites-available directory, I created the reverse-proxy.conf file and wrote the following code in it:
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
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;
}
}
And i was able to access the site using my ip address. But now, how do I access the site by domain name? For example: example.com
Did you create a custom conf file in /etc/nginx/conf.d/ directory?
Working file /etc/nginx/conf.d/reverse-proxy.conf
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:5000;
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;
}
}
Make sure after the changing nginx configuration reload or restart.
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;
}
}
I am using ActionCable in rails 5.2 and deployed the code on AWS with nginx server.
Previously WebSocket was working when I was working on http but when i have implemented SSL, it stopped working. For SSL I have implemented load balancer in AWS. I am using Unicorn as rails application server.
my ActionCable url is:
SOCKET_URL: wss://example.com/cable
Started GET "/cable/"[non-WebSocket] for 182.74.85.106 at 2019-10-30 14:32:05 +0000
Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: )
Finished "/cable/"[non-WebSocket] for 182.74.85.106 at 2019-10-30 14:32:05 +0000
configuration in my production.rb file is:
config.action_cable.url = ENV["SOCKET_URL"]
ActionCable.server.config.disable_request_forgery_protection = true
my nginx conf is:
upstream unicorn {
server unix:/usr/share/nginx/html/demo_app/shared/tmp/unicorn.demo_app.sock fail_timeout=0;
}
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html/demo_app/current/public;
try_files $uri/index.html $uri #unicorn;
location #unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
You can paste below lines in your nginx.conf and try.
location /cable {
proxy_pass http://unicorn/cable;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
I have two subdomains, app.mydomain.com and v1.api.mydomain.com, pointing to the same IP. I want app.mydomain.com to be proxied to localhost:5000 and v1.api.mydomain.com to be proxied to localhost:1337.
The following configuration does it (app.mydomain.com/... is served by localhost:5000 and v1.api.mydomain.com/... is served by localhost:1337) except for one thing: the root of v1.api.mydomain.com (with or without a trailing slash) isn't served by localhost:1337, it is served by localhost:5000 (app.mydomain.com) and therefore it doesn't display what I expect. How is this possible?
My first configuration file in sites-enabled:
server {
listen 80;
server_name app.mydomain.com;
location / {
proxy_pass http://localhost:5000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
My second configuration file in site-enabled:
server {
listen 80;
server_name v1.api.mydomain.com;
location / {
proxy_pass http://localhost:1337/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
To make sure that the problem wasn't a redirection of some sort by the server running on localhost:1337, I shut it down and the problem is still there, so it really is something with my nginx configuration. Thanks for helping.
I have a Single Page Application running on a node server serving angular at www.xxx.com. This is currently working.
I am trying to server a second Node application named www.yyy.com however when I set up the NGINX server blocks it is defaulting to the NGINX welcome page.
www.xxx.com NGINX server block (Which is working fine):
server {
listen 80;
listen [::]:80;
server_name xxx.com.au www.xxx.com.au;
return 301 https://xxx.com.au$request_uri;
}
server {
listen 443;
server_name xxx.com.au www.xxx.com.au;
location / {
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;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:3000/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
}
ssl on;
ssl_certificate /etc/letsencrypt/live/xxx.com.au/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xxx.com.au/privkey.pem;
}
www.yyy.com Server block: (Currently only serving welcome page)
server {
listen 80;
server_name yyy.com www.yyy.com;
location /site {
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;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:3002/;
proxy_redirect off;
}
}
I have all the DNS set up and the host names set up on my droplet as well. I am using Vultr running Ubuntu if that helps.
I have added both via symbolic link to Sites-available and the line is present in the conf file.
EDIT: As Henry pointed out I was server /site
location /site {
You're serving the app at /site and not /.
You can map different different config blocks to different URLs, so you could e.g. route /example to a different node server if you wanted.
Replacing location /site { with location / { as for your working block will serve your node application at the root. With no configuration for the root node nginx routes it to its default page.