Stop nginx redirect to proxy_pass location - nginx

I have two domains: abc.com and def.com. I am running a Django application behind nginx. Single django application has two apps running under different URL, app1 is running under url: localhost/corp and app2 is running under url: localhost:/service.
Now I want to server /corp on abc.com and /service on def.com domain.
For this I have done this NGINX configuration:
server {
listen 80;
server_name abc.com;
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/site/site.sock:/corp;
}
}
server {
listen 80;
server_name def.com;
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/site/site.sock:/service;
}
}
But the configuration is not working this way, when I visit abc.com, I get redirected to abc.com/corp and when visiting def.com, its redirected to def.com/service. Instead, I want /corp content to be served on abc.com root and /service content on def.com root domain itself. How can I modify this configuration to achieve this?

Related

nginx config to create subdomain from domain proxy_pass

I am trying to setup a domain and subdomain for my domain name in nginx server for www.example.com/users to www.people.example.com
i am able to configure subdomain but when i typed url in browser of subdomain url it is redirecting to www.example.com/users
But i need it to be in subdomain
is there anything that i missed in nginx config? please provide me any suggestion nginx config for subdomain
server
{
server_name people.example.com www.people.example.com;
error_log /var/log/nginx/error.log;
location / {
proxy_pass http://example.com/users$request_uri;
proxy_set_header "Host" $host;
proxy_redirect http://$host/users http://$host;
}
And also suggest me config for www.example.com to block access via www.example.com/users but can be accessed via www.people.example.com
Try redirecting from a separate server stanza. Then remove the proxy_* commands from the people.example.com server.
server {
server_name example.com www.example.com;
location = /users {
return 301 http://people.exxmple.com;
}
}

How can a request resolve to a different domain while keeping URI information?

I have 2 domains domain.xyz and domainxyz.com
I have the boilerplate for a dynamic routing service set up on domain.xyz which serves domain.xyz/example-uri.
I would like to make domainxyz.com/example-uri resolve to domain.xyz/example-uri
On the server I am using Nginx to direct requests on port 80 to the React app
instead of using a dns redirect to resolve the .com to the .xyz (which is what I was initially doing), direct both domains to the nginx server. Then configure the nginx server like this:
source/explanation: https://www.nginx.com/blog/creating-nginx-rewrite-rules/
server {
listen 80;
server_name www.domainxyz.com domainxyz.com;
location / {
return 301 $scheme://domain.xyz$request_uri;
proxy_pass http://localhost:3000;
}
}
server {
listen 80;
server_name www.domain.xyz domain.xyz;
location / {
proxy_pass http://localhost:3000;
}
}

Nginx proxy_pass rule Issue

So, I'm running some docker containers serving on ports 8090 and 8000. Now I want to setup Nginx reverse proxy to handle requests to both of these ports internally. The main URL http://milesblock.com changes automatically to http://milesblock.com/#/
I have setup a proxy_pass in nginx as follows-
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name milesblock.com;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:8090;
}
location /api {
rewrite ^/api(.*) $1 break;
proxy_pass http://127.0.0.1:8000;
}
}
Now, the issue is because of the automatic change of the URL to http://milesblock.com/#/ the redirect to both the ports is not working as intended. Only the /api proxy is working with the above config file.
How do i configure the proxy to handle the traffic on port 8090 and also the api calls on port 8000?

Nginx server block ERR_NAME_NOT_RESOLVED

I am running Nginx on an Ubuntu 14.04.5 server. I am trying to set up a new server block but when I navigate to the URL I see this error:
My configuration for this virtual host is below.
The directory that I'd like my subdomain to point to is /var/www/vhosts/ny-video.splashpreviews.com
In /etc/nginx/sites-available is my server block file. The server configuration part of that file is below:
server {
listen *:80;
listen [::]:80;
root /var/www/vhosts/ny-video.splashpreviews.com;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name ny-video.splashpreviews.com;
}
I then enabled the server block and restarted Nginx. Is there something I am missing in the process or something I am doing wrong that is causing this to not work? Any guidance would be appreciated. Thank you.
You need to add splashpreviews.com site to configuration and allow locations of the server. There can be several location sections, limiting access to each subdirectory.
http {
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
include /etc/nginx/mime.types;
....
server {
listen 80;
server_name splashpreviews.com www.splashpreviews.com;
location / {
allow all;
}
....
}
server {
listen 80;
server_name ny-video.sp.com;
location / {
allow all;
}

How to configurate nginx and uwsgi to redirect calls from path to subdomain?

i am running a flask app on uwsgi and nginx. They website serves two functions:
/admin:for backend administration
/api:for rest api
I want all api calls go through the subdomain:api.mysite.com.
It is runing very well if i call api like www.mysite.com/api/v1/cities.
what if i want to call the api this way, api.mysite.com/v1/cities?
How could i manage to do this?
I managed to get it working by setting proxy_pass on nginx conf:
server {
listen 80;
server_name localhost;
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/app.sock;
}
}
server {
listen 80;
server_name api.mysite.com;
location / {
proxy_pass http://localhost/api/;
}
}
still thinking if it is the best solution and is there any overhead to the server?

Resources