I have setup subdomain virtual host but its not working getting 522 error.
main domain is working fine. I have also check nginx error log but its not showing any error.
Envirnment
Ubantu 18.10
I have already setup DNS and also check nginx error log but don't see any nginx errors.
server {
listen 80;
listen [::]:80;
server_name subdomain.com www.subdomain.com;
root /var/www/html/subdomain.com/public_html;
error_log /var/log/nginx/error.log;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
anyone please suggest possible solution to fix this issue.
Thanks
Related
I have a t2 server (AWS EC2 server) that I want to simply serve an HTML file as the root:
http://my_ip/ -> gives me my index.html
and another one serving a reverse_proxy
http://my_ip/api -> gives me my "API" (or whatever runs on the reverse proxy IP)
So I configured the Nginx as the followings:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location /api {
proxy_pass http://127.0.0.1:3000;
}
}
Simple enough, in this configuration, my index.html is showing up. But whenever I'm trying to access the "reverse proxy" (/api), I get 504 Gateway Time-out error.
So I tried to "switch places", I gave the reverse-proxy the "root" / and the index.html the "/api".
Getting this configuration:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
proxy_pass http://127.0.0.1:3000;
}
location /api {
try_files $uri $uri/ =404;
}
}
This way, the reverse proxy is doing OK! (from /), and when I try to reach index.html (from /api), I'm getting 504 Gateway Time-out error.
So I figured that something is wrong with the "sub-directories" configuration. I tried such configurations on many servers before (mainly from DigitalOcean and others) and never ran into something like that.
My guess is it got something to do with the t2 (EC2) NAT configuration (maybe?). But I'm not so sure.
Googling the issue didn't raise any answers.
There's Ubunutu 20.04 installed on the t2 server, It's "brand new" (nothing was installed but Nginx, Node & NPM - was done by me, "by the book" installations with no needed configurations or file changing).
Note that I don't have a domain yet, I was thinking of trying to server the reverse proxy on a subdomain but I have no way to do it at this point, that's why I tried to do it via a subdirectory.
Thanks.
I'm a newbie in Nginx, trying to learn.
I have the server under mydomain.com and my static site under my-app.mydomain.com
All the paths are relative, so images/image.png resolves to my-app.mydomain.com/images/image.png.
I also have a second app, new-app.mydomain.com which has the same issue, the relative paths are trying to be resolved to mydomain.com
I don't know how to fix this and I would like to avoid having to make all paths absolute. Also, I would like a solution that allows me to keep adding new locations blocks for the new app and load the resources. I want to avoid some restrictive that could work for the main app but not for the other.
location /new-app {
proxy_ssl_server_name on;
proxy_pass "mydomain.com";
}
I will appreciate help.
Locations inside a server can help you configure website/content that need to be displayed on sub-routes of website. Sub-domains need to be configured in a seperate nginx file similar to main domain in which you can add as many location as per your requirement.
Nginx files:-
mydomain.com
server{
listen 80 default_server;
listen [::]:80 default_server;
server_name mydomain.com;
location / {
proxy_ssl_server_name on;
proxy_pass "mydomain.com"; # This should be server with port on which your server is running on VM(virtual machine)
root /var/www/html/mydomain.com; #In case you want to server static files
try_files $uri $uri/ /index.html;
}
}
new-app.mydomain.com
server{
listen 80 default_server;
listen [::]:80 default_server;
server_name new-app.mydomain.com;
location / {
proxy_ssl_server_name on;
proxy_pass "new-app.mydomain.com"; # This should be server with port on which your server is running on VM(virtual machine)
root /var/www/html/new-app.mydomain.com; #In case you want to server static files
try_files $uri $uri/ /index.html;
}
}
I don't know what's wrong. I don't get any warnings in logs. I've similar config to this
How to exclude specific subdomains server_name in nginx configuration
I want to create subdomain us.example.io I'm using ping to check it
ping us.example.io
ping: cannot resolve us.example.io: Unknown host
nginx.config
server {
server_name *. us.example.io us.example.io;
listen 80;
root /usr/share/nginx/html/bint;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.html;
}
}
server {
server_name us.example.io;
listen 80;
return http://www.google.com;
}
The problem has nothing to do with nginx. The error suggests that you haven't configured a DNS record for the domain.
I have nginx running on my ubuntu 14.04 droplet, with one website at the moment. It was online and accessible until today, since I'm now getting a ERR CONNECTION REFUSED when I type in the url. It doesn't work on other devices/networks as well, but I can ping it...
Which lets me to believe there is suddenly something wrong with my configuration (although I haven't changed anything lately). Within my /etc/nginx/sites-enabled/default file my settings are as followed:
server {
listen 80;
server_name paulvanmotman.com www.paulvanmotman.com;
rewrite ^ https://www.$server_name$request_uri? permanent;
}
server {
listen 443 ssl;
root /var/www/paulvanMotman;
index index.html index.htm;
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 168h;
}
ssl on;
ssl_certificate /etc/nginx/ssl/ssl-bundle.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
server_name paulvanmotman.com www.paulvanmotman.com;
location / {
try_files $uri $uri/ =404;
}
}
If anyone could help me out I would greatly appreciate!
Kind regards,
Paul
Solved the problem myself! For anyone who is interested, this was the problem I had: Webserver with nginx working until .save file created
I was asked to make a rewrite rule to redirect a virtual host subdomain to another virtual host managed by the same Nginx server. That works fine but I'd like to mask the URL redirect in the browser.
There is a configuration file for each virtual host: subdomain.mydomain.com.conf configuration file was made from original www.mydomain.com.conf with required substitutions.
This is www.mydomain.com.conf virtual host configuration file:
server {
listen 127.0.0.1:80;
listen 443 ssl;
server_name www.mydomain.com;
access_log /var/log/nginx/www.mydomain.com-access_log main;
error_log /var/log/nginx/www.mydomain.com-error_log;
root /var/www/html/www.mydomain.com;
index index.php index.html index.htm;
...
location / {
try_files $uri $uri/ /index.php?$args;
}
...
I made a Nginx rewrite rule to redirect URLs beginning with www.mydomain.com/subdomain to subdomain.mydomain.com:
location /subdomain {
rewrite ^/$ subdomain.mydomain.com$request_uri last;
}
I found a link that explains how to make an internal redirect :
http://www.claudiokuenzler.com/blog/436/nginx-rewrite-url-examples-with-without-redirect-address#.VFKqiYXXqPK
I made several attempts but the redirect is always shown.
As I'm new to Nginx, can somebody help me out ?
best regards,