I have one domain myartistbook.in, which is working fine. I want to create a sub-domain for it named adminpanel.myartistbook.in. The steps I followed are:
Added sub-domain name to /etc/hosts
127.0.0.1 localhost
***.***.***.180 myartistbook
***.***.***.180 adminpanel.myartistbook
edited /etc/nginx/nginx.conf:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name myartistbook.in www.myartistbook.in;
root /root/krim.com;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 80;
root /root/sites/adminpanel.com;
server_name adminpanel.myartistbook.in www.adminpanel.myartistbook.in;
index index.html;
location / {
try_files $uri $uri/;
}
}
}
Added a file named adminpanel.com inside /etc/nginx/sites-available.
server {
listen 80;
server_name www.adminpanel.myartistbook.in;
server_name ***.***.***.180;
root /root/sites/adminpanel.com;
index index.html;
access_log /var/log/nginx/adminpanel.com.access.log;
error_log /var/log/nginx/adminpanel.com.error.log;
location / {
try_files $uri /index.html =404;
}
}
Linked the above server block into /etc/nginx/sites-enabled
sudo ln -s /etc/nginx/sites-available/adminpanel.com /etc/nginx/sites-enabled/adminpanel.com
Restarted nginx with
sudo service nginx restart
While accessing the site I'm getting error adminpanel.myartistbook.in’s server IP address could not be found.
Am I missing any step?
Together with server-side configurations involving domains and subdomains in server_name, you need to make sure that your DNS records for myartistbook.in are properly configured as well.
Have you added a DNS record to point adminpanel.myartistbook.in to your server? You can either add an A record or a CNAME record for this. Looking at a quick check using whatsmydns.net for adminpanel.myartistbook.in, it seems you missed this step. Please check the documentation of your domain registrar on how to do this.
After adding the records, do a quick check again using whatsmydns.net if your CNAME/A record has taken effect.
In your step 3, modify the server_name to adminpanel.myartistbook.in without the www, unless this is actually your intention to use the whole www.adminpanel.myartistbook.in, which I don't think is the case here because you attempted to access it without the www:
adminpanel.myartistbook.in’s server IP address could not be found.
Also, it's probably good to use a different server {} block when referring to IP addresses as server_name then redirect to the domain/subdomain. However, redirecting from IP Address going to your domain/subdomain may be not be the priority now. Suggest to remove that line in the meantime.
Then run a quick nginx -T to check for errors in your configuration. If the check is successful, reload your nginx web server and try accessing the subdomain again.
Hope that helps!
Related
I'm having the following issue :
My centos 7 vps is configured with nginx and two server-blocks (vhosts)
For both domains I can access the web-page using www.domain.tld but not using domain.tld.
No error or access logs are generated when accessing domain.tld
Dns record were checked and are pointing to the servers IP address with an empty A record ( the same dns record worked properly when server was configured with ubuntu 18.04, iRedMail, nextcloud and two websites).
The error message in browser is : "This site can’t be reached. domain.tld refused to connect."
Below are the config files (nginx and one domain), I've included the path for reference:
nginx.conf
#cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;
server {
listen 80 default_server;
server_name "";
return 444;
}
}
* default_server is used to prevent access to nginx welcome page when accessing http:\serverIP . Behavior is not affected by returning this config to nginx default.
domain config
# cat /etc/nginx/sites-enabled/domain.tld.conf
server {
listen 80;
server_name domain.tld www.domain.tld;
location / {
root /var/www/domain.tld;
index index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# Setting log locations
access_log /var/log/nginx/domain.tld-access.log;
error_log /var/log/nginx/domain.tld-error.log debug;
}
I must mention that the purpose of this VPS is to learn basic Linux sysadmin, therefore there is no real data or restrictions and also that is my first contact with centos.
Thanks for your time and effort.
L.E.
Adding "127.0.0.1 www.domain.tld domain.tld" to /etc/hosts does not fix the issue. Both domains are real domains with dns server and all records are replicated. Furthermore using trace-route to domain VPS IP is reached.
Nginx config is successful validated
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Upon further investigations I've noticed that no request appear in access or error log (error set to debug) when accessing domain.tld but they do for www.domain.tld
Witch would send me straight to DNS but checking DNS using a few dig online versions everything seems OK, both domain.tld and www.domain.tld point to the correct VPS ip
After loosing almost two days trying to figure out what is causing this issue finally, non-intentionally I've accessed the website while I was remote on another PC and to my utmost surprise everything worked just fine.
Now I'm sure that I've cleared my DNS cache multiple times but apparently the issue was generated by plugin httpsEverywhere.
Thanks and I promise to try harder next time :D
It seems like a simple problem but I cannot find any official information about how to fix it.
The problem: Deploying an EmberJS app to Nginx - all routes return 404's.
The root route / works just fine. However any route besides / fails & returns 404's. Here's how I have my nginx.conf setup:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/ivo/myapp;
index index.html;
location / {
include /etc/nginx/mime.types;
try_files $uri $uri/ /index.html?/$request_uri;
}
}
}
This config is largely based on the nginx.conf that comes with the Nginx Docker image, which I am using.
From what I understand about Nginx, the location / block should be handling my routes, but for some reason it is not.
As a side note, I am shocked that EmberJS does not have any documentation about this at all. I even tried their Nginx config from their deployment section and it too did not work - https://ember-cli.com/user-guide/#deployments
Found & "fixed" the problem. The underlying issue is that the information provided on the Nginx DockerHub page is misleading. It says:
"If you wish to adapt the default configuration, use something like the following to copy it from a running nginx container"
And it provides this line as an example:
"COPY nginx.conf /etc/nginx/nginx.conf"
However, the file located at /etc/nginx/nginx.conf was not the file I needed. Instead, the file I needed to change/replace was located here : "/etc/nginx/conf.d/default.conf"
The code I pasted above in the Question portion worked fine; it was the location that was wrong.
I have a CentOS 7 server where I have running some Golang apps. As you know, every app is running on his own port, lets say: 9000,9100,9200 and so on.
Now, I have installed Nginx to serve all the websites, I have a domain for every site and I want to receive all the petitions in the port 80 and then just based on the domain i have to redirect to the application that corresponds.
By now,am trying to make it with one of the site that is running in the port 9094, I have no experience with Nginx so I was just reading to know what to do,but it seems like it's not working. in the file nginx.conf I added these lines:
server {
listen 80;
server_name mydomain.com;
access_log logs/mydomain.log main;
location / {
proxy_pass http://127.0.0.1:9094;
}
}
I have to mention that I didn't delete these lines that comes for default in the file:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Is the configuration ok? and will allow me to add more sites? Thank you
If I ping to the domain everything is ok, but if I open the domain in the browser then I get status code 502
EDIT:
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name mydomain.com;
access_log logs/mydomain.log main;
location / {
proxy_pass http://127.0.0.1:9094;
}
}
}
Your server configuration looks okay and the 502 Status Code means you didn't configure the Go servers correctly. Specifically, Nginx did exactly what you expected it to, proxied the request to and from your upstream, but received an invalid response from your Go server.
Background: I've installed and currently maintaining a OTRS v4.0 system with nginx as web server. The system was running until I added ssl port as well in nginx.conf and since then, I'm trying to connect to the webpage
http://localhost/otrs/index.pl
but is not responsive and displaying nginx error! The Page you are looking for is not found.
I removed the ssl sections from the nginx.conf file but still I'm not able to get back my previous state of web page.
In the error.log file it displays that it is not able to find the index.pl file open() "/usr/share/nginx/html/otrs/index.pl" failed (2: No such file or directory)
This message is logged whenever I hit the URL(http://localhost/otrs/index.pl).
In the otrs.log file it just logs in the PID.
Is there any way-out without having to re-install the otrs again? or any other log files I've missed to check
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
#debug_connection 10.0.2.15;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
#listen 80;
server_name server.unixmen.local;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
?
Thanks in advance!
You have confused your default servers and nginx is trying to serve the wrong content.
OTRS uses fastcgi and will have it's own config file in the /etc/nginx/conf.d directory. The file you have posted is the default nginx config which has little to do with OTRS.
Change your listen directive to:
#listen 80 default_server;
listen 80;
This will discourage the default nginx config from handling unknown host connections to https://localhost and assuming it worked previously then the system should work again. If not then post the OTRS config from /etc/nginx/conf.d/something.conf and we'll be able to see what else is happening.
Thanks for your replies. I got the solution!
Perhaps, it was a silly mistake from my end ;)
First of all, I forgot to mention in the question that I also ran another web server on the same machine, Apache. At the initial stage, both the servers were configured at same port ->80. So, the OTRS was running on Apache instead of nginx(I'm using this as well for another purpose!). Later on, to avoid the confusion i changed the port in Apache configuration from 80 to 8080 and right from this moment the server stopped serving the OTRS.
So now, when I use http://localhost:8080/otrs/index.pl it's working correctly.
Next time, I would take enough care to change server configuration wisely while working on multiple web servers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I recently had to set up a nginx server on a centOS 7 server.
In order to run the dataiku software.
Every thing seems to run fine but once i try to access the pages i get absolutely nothing.
With elinks in local i manage to get the nginx default web page but not from my browser so i think it comes frommy nginx configuration.
here is my nginx.conf :
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
And here is the default.conf included file :
server {
listen 80 default;
server_name _;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
I really need this server running properly and being accessible do you have any idea ?
Thank you for reading.
you should add a new rule on public zone, because CentOS 7 has a firewalld.
Try:
firewall-cmd --zone=public --add-service=http
and go head!
Add the rule to the permanent set and reload FirewallD:
sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --reload
That should work!
You missed proxy_pass configuration which is actually translate all requests from backend to the outside via HTTP port 80 in your case:
server {
# Host/port on which to expose Data Science Studio to users
listen 80;
server_name _;
location / {
# Base url of the Data Science Studio installation
proxy_pass http://DSS_HOST:DSS_PORT/;
proxy_redirect off;
# Allow long queries
proxy_read_timeout 3600;
proxy_send_timeout 600;
# Allow large uploads
client_max_body_size 0;
# Allow protocol upgrade to websocket
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Official documentation is pretty clear on that: http://doc.dataiku.com/dss/latest/installation/reverse_proxies.html
Make sure you have uptodated Nginx to be able to serve WebSocket requests.