I can't restart nginx because I got [emerg] 6594#6594: bind() to 0.0.0.0:443 failed (98: Address already in use). How does multiple server block work? Without the staging server block my config is working fine.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name api.example.com;
location / {
proxy_pass http://localhost:3001;
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;
}
}
server {
listen 443;
server_name staging-api.example.com;
location / {
proxy_pass http://localhost:3002;
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;
}
}
netstat -anp | grep :443 chgeck which app take over the port 443,and if not necessary, kill it and then restart nginx
Related
I'm trying to run node-media-server on a EC2 instance, but i a'm not able to make OBS to connect to the server, here is my Nginx config:
server {
listen 8000;
listen 1935;
server_name example.com;
location / {
proxy_pass http://localhost:$server_port;
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;
}
}
And here is my security group set up:
Any idea what is going on?
Thanks in advance,
I found the problem, the first thing is to setup Nginx to listen on the port 80 only as node-media-server takes care of listening on the ports 8000 and 1935
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:$server_port;
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;
}
}
Second thing is to make sure the ports 8000 and 1935 are open in the server as by default they are not.
Hope it helps to anyone with the same problem.
I am installing a site under my machine. I have a NodeJS server that listens on port 4000.
I am using an NGINX reverse proxy, so that it is accessible from port 80. Here is the following configuration in / sites-availabes
upstream site {
server 127.0.0.1:4000;
}
server {
listen 80;
server_name site.infra.monsite.blog;
location / {
proxy_pass http://site;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
But I can't access my site from site.infra.monsite.blog; which points to port 80 of the machine.
Are there any ports to open like on Windows, or an NGINX configuration that I missed?
Yet when I do "curl -X GET http://localhost/": It works on the machine.
Thanks for your help.
Try this:
upstream site {
server 127.0.0.1:4000;
keepalive 64;
}
server {
listen 80;
server_name www.example.com;
return 301 https://www.example.com$request_uri;
}
location / {
proxy_pass http://site;
proxy_http_version 1.1;
proxy_redirect off;
proxy_pass_header Set-Cookie;
proxy_set_header Connection 'upgrade';
proxy_set_header Upgrade $http_upgrade;
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-NginX-Proxy true;
proxy_pass_header X-XSRF-TOKEN;
proxy_read_timeout 240s;
}
I have a test server and try to serve apidoc on node.js with a reverse proxy but in the browser I see a empty page.
apidoc serves with http-server on port 3034 in node.js and I run it with pm2 and this is my default configuration in site-available
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 /docs {
proxy_pass http://localhost:3034;
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;
}
location / {
proxy_pass http://localhost:3000;
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;
}
}
I have three web sites working with NodeJS. I want to publish with NginX, therefore have installed all its requirements. For my domain, I'd like to publish over https, whereas for sub-domains, I'd like to publish over http. My problem is that the publishing fails for sub-domains.
I have written the config files in /sites-enabledfolder.
/default:
server {
listen 443 ssl;
server_name www.my-domain.com;
ssl_certificate /var/www/my-domain/server/config/certificates/www_my-domain_com.crt;
ssl_certificate_key /var/www/my-domain/server/config/certificates/www_my-domain_com_nokey.key;
location / {
proxy_pass http://localhost:8080;
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;
}
}
server {
listen 80;
server_name www.my-domain.com my-domain.com;
return 301 https://www.my-domain.com$request_uri;
}
server {
listen 443;
server_name my-domain.com;
return 301 https://www.my-domain.com$request_uri;
}
/subdomain.my-domain.com:
server {
listen 80;
server_name crm.my-domain.com;
access_log /var/log/nginx/crm.my-domain.com.log;
location / {
proxy_pass http://localhost:8081;
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;
}
}
/subdomain2.my-domain.com:
server {
listen 80;
server_name support.my-domain.com;
access_log /var/log/nginx/support.my-domain.com.log;
location / {
proxy_pass http://localhost:8082;
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;
}
}
I have followed along a digital ocean tutorial to deploy my node.js app onto VPS. Everything is working, but instead of reaching the app from myDomain.com, it's only available through myDomain.com:3700. myDomain.com only shows "Success! Virtual host is set up!"
/etc/nginx.sites-available/default:
server {
listen 3700;
server_name myDomain.com;
location / {
proxy_pass http://127.0.0.1;
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;
}
}
Oddly, if I change it to:
server {
listen 80;
server_name myDomain.com;
location / {
proxy_pass http://127.0.0.1:3700;
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;
}
}
and enter sudo nginx -s reload, nothing changes.
in my node app, I have:
...
var port = 3700;
...