I am facing an issue while working on a project. For example i had a ubuntu running with nginx configuration. I had configure wildcard with nginx like:-
main domain : xyz.com
wildcard : a.xyz.com, b.xyz.com working.
The above config is working with https with the help of let encrypt.
Here is my problem, that i am facing right now.
I want that if i give someone a.xyz.com, and then that someone want that a.xyz.com will listen that www.someone.com. Is that possible or not this is the question i am lokking into and if yes then please suggest how??
And if you think question header is nothing to do with my question then let me clear that the same issue i am facing shopify guys are doing some how.
Thanks for your precious time.
You can below configuration
server {
listen 80;
listen 443 ssl;
server_name a.xyz.com;
ssl_certificate /path/to/cert/YourCert.pem;
ssl_certificate_key /path/to/cert/privkey.pem;
location / {
proxy_pass https://www.someone.com;
}
}
server {
listen 80;
listen 443 ssl;
server_name b.xyz.com;
ssl_certificate /path/to/cert/YourCert.pem;
ssl_certificate_key /path/to/cert/privkey.pem;
location / {
proxy_pass https://www.someone2.com;
}
}
Related
I would like to understand why these server blocks are not working as I would expect them to do.
I have over 1000 domains and I've tried to find a solution to reduce redundance. Therefore I wanted to redirect all http requests to https and all www urls to non-www urls globally with one single server block.
I know this is a topic which has been discussed many times and the gold standard is probably not to do so but I'm not sure why to be honest.
Anyway I've come up with a solution which is working like intended but one thing is really bothering me:
Both
www.example.com
http://www.example.com
are redirecting to example.com as expected.
But using https://www.example.com is not redirecting at all and does not find the proper certficate.
I had to add a second server_name with the www like www.example.com to the serverblock to make it work (btw. the certificates are valid for both www and non-www).
Why does it not work without it? Why is https://www.example.com not redirecting to example.com? Can any expert explain this to me pls?
Thank you so much!
This my 'global' server block
server {
listen 80;
listen 443;
server_name "~^www\.(.*)$" ;
return 301 https://$1$request_uri ;
}
This is the server block structure I've been using for all domains:
server {
listen 80;
listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
server_name domain1of1000.com;
ssl_certificate [path1of1000]/fullchain.pem;
ssl_certificate_key [path1of1000]/privkey.pem;
}
Sorry for limited understanding on Nginx, Iam new to Nginx.
I have a webapp running on React and Nginx. Recently I received the SSL certificates for my website. I tried to configure the website and it worked partially. The problem is when I tried to open "https://example.com", the SSL certificates are visible here but its showing nginx default home page. While when I open "http://example.com" it shows all the webcontent.
I attempted to:
change the port from 80 to 443
Reinstall nginx.
But nothing seems to work. Here is my nginx confs at the moment:
/etc/nginx/sites-available/example.org
server {
listen 443;
listen [::]:443;
ssl on;
ssl_certificate /etc/nginx/ssl/bundle.cer;
ssl_certificate_key /etc/nginx/ssl/example.key
root /var/www/html;
server_name example.org;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 80;
listen [::]:80;
server_name _;
return 301 https://example.org;
}
/etc/nginx/conf.d/www/example.org.conf
server {
listen 80 default_server;
server www.example.org;
location / {
root /usr/share/nginx/html;
index index.htm; index.html;
}
}
Note: I reload nginx at every new attempt.
Please help where am I going wrong.
Keeping just 1 file for config works for the above problem. I kept the "default" conf at "/etc/nginx/sites-available"
I have configured my nginx config file in /etc/nginx/sites-enabled
filename:- subdomain.xyz
But When I am using proxy_pass in location directive it is giving me ERR_INCOMPLETE_CHUNKED_ENCODING in chrome browser.
My config file:-
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name subdomain_name;
include /etc/nginx/snippets/ssl;
location / {
proxy_pass http://ip_address:port_number/services;
}
}
Can anyone help me on this.
Thankyou in advance
I have solved this problem using add proxy_hadder in nginx config file
I have the following server block
server{
listen 80;
server_name foo.domain.com;
root /some/rails/app;
passenger_enabled on;
}
However any subdomain under domain.com is matched using this block and is served by my rails app, so a.domain.com, nothing.domain.com, all are being sent to the rails app, how can I prevent this wildcard behavior which I didn't ask for ?
You can drop all traffics that wasn't to a domain explicitly defined in another server configurations
server {
listen 80 default_server;
server_name _;
deny all;
}
I have a site which is ran with nginx, and with the structure where we have a load balancer, and currently only one web server behind it (currently no real traffic so one web server only).
Anyways, in load balancer nginx config, we forced HTTPS on each request:
server {
listen 80;
server_name www.xyz.com xyz.com
return 301 https://www.xyz.com$request_uri;
}
This works fine, but now I want to say "on this subdomain - dev.xyz.com, allow HTTP too and don't do the forcing".
At first, the server_name param was "any", and thought that might be the problem, so I specifically typed the names as in the above samples, and when I type http://www.dev.xyz.com, I get redirected back to the https://www.xyz.com.
Below server block, we have SSL definitions too:
server {
listen 443;
ssl on;
ssl_certificate /etc/nginx/ssl/xyz.com.pem;
ssl_certificate_key /etc/nginx/ssl/xyzPrivateKeyNginx.key;
keepalive_timeout 70;
server_name www.xyz.com;
root /usr/local/nginx/html;
client_max_body_size 25M;
client_body_timeout 120s;
# Add trailing slash if missing
rewrite ^([^\.]*[^/])$ $1/ permanent;
}
Thanks! :)
it turned out the solution was simple, I only inserted a simple redirect:
server {
listen 80;
server_name www.dev.xyz.com
location / {
proxy_pass http://xxyyzz;
}
}
Where xxyyzz is:
upstream xxyyzz{
ip_hash;
server 10.100.1.100:80;
}
Thanks anyways!