i have this nginx config:
server {
listen 80 default_server;
index index.html index.htm;
server_name myserver;
location / {
root /var/www/html/;
index index.html;
}
location /doc/ {
root /var/www/html2/;
index index.html;
}
location /api/ {
proxy_pass http://127.0.0.1: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;
}
}
and I don't understand why the /doc/ route not works, it returns 404 Not Found? The /api/ and / routes work fine.
I already searched and found this https://serverfault.com/questions/684523/nginx-multiple-roots
Thanks
No i found the right way, in case anyone else have the same problem.
server {
listen 80 default_server;
index index.html index.htm;
server_name myserver;
root /;
location / {
alias /var/www/html/;
}
location /doc {
alias /var/www/html2/;
}
location /api/ {
proxy_pass http://127.0.0.1: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;
}
}
Related
So I'm trying to redirect port 80 to 443. I'm also trying to do a proxy forwarding to locahost:4000 with socket.io. are both correct or incorrect these are in nginx/sites-enabled/ap.kosherup. Not sure why the server { got cut off from rest of code. Also where would I add the security headers in the file? I am a noob.
server {
listen 80;
listen [::]:80;*
root /var/www/api.kosherup/html;
index index.html index.htm index.nginx-debian.html;
server_name api.kosherup www.api.kosherup;
return 301 https://api.kosherup.xyz$request_uri;
location /socket.io {
proxy_set_header Host $host;
proxy_pass http://localhost:4000/socket.io/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /v1 {
proxy_pass http://localhost:4000/v1;
}
}
server {
listen 443;
listen [::]:443;
root /var/www/api.kosherup/html;
index index.html index.htm index.nginx-debian.html;
server_name api.kosherup www.api.kosherup;
location /socket.io {
proxy_set_header Host $host;
proxy_pass http://localhost:4000/socket.io/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /v1 {
proxy_pass http://localhost:4000/v1;
}
}
I want to test nginx with docker with two apps before i deploy online.
I am trying to set different local domains. The localhost domain is working but if I try localhost2 as a domain, nginx doesnt get it in the browser (the dns must not be configured). So I tried with local ip adress (192.168.0.2) as a domain name but it is not working.
What should i put so i can access my first website at http://localhost and my second at a http://local_ip_adress?
This is the nginx config file :
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html/build;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://backend:8000/api;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 20M;
}
location /wagtail {
proxy_pass http://backend:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Script-Name /wagtail;
client_max_body_size 20M;
}
location /djangostatic {
alias /app/static;
}
location /media {
alias /app/media;
}
}
server {
listen 80;
server_name 192.168.0.2;
location / {
root /usr/share/nginx/html/build2;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://backend2:8000/api;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 20M;
}
location /wagtail {
proxy_pass http://backend2:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Script-Name /wagtail;
client_max_body_size 20M;
}
location /djangostatic {
alias /app/static;
}
location /media {
alias /app/media;
}
}
I have below nginx config file. I'd like to add another route which maps everything else to http://kibana-entrypoint:5601/. How can I do that in nginx?
http {
server {
listen 8080;
server_name localhost;
location /es/ {
proxy_pass http://es-entrypoint:9200/;
}
location /health {
proxy_pass http://es-entrypoint:9200/_cluster/health;
}
location EVERYTHING_ELSE {
proxy_pass http://kibana-entrypoint:5601/;
proxy_redirect off;
proxy_buffering off;
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 an issue with a freshly configured Nginx setup on Debian 9.
My site loads fine using https, but I get a 404 Not Found when I access it using http.
I tried removing the ssl certificate, it works however i need the location /webex/receive in https and /ping and /mailgun in http.
See my edited down server block:
server {
listen 80;
listen 443 ssl;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
location /ping {
proxy_pass http://xx.xx.xx.xxx: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;
}
location /mailgun {
proxy_pass http://xx.xx.xx.xxx: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;
}
location /webex/receive {
proxy_pass http://xx.xx.xx.xxx: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;
}
}
All location (/ping, /mailgun and /webex/receive) work in https but I only want /webex/receive in https and the others locations /mailgun and /ping in http.
I found the solution
server {
listen 80;
listen [::]:80;
root /var/www/xx.xx.xx.xxx/html;
index index.html index.htm index.nginx-debian.html;
server_name xx.xx.xx.xxx www.xx.xx.xx.xxx;
location / {
try_files $uri $uri/ =404;
}
location /ping {
proxy_pass http://xx.xx.xx.xxx:3000;
}
location /mailgun {
proxy_pass http://xx.xx.xx.xxx:3000;
}
}
server {
listen 443 ssl;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
location /webex/receive {
proxy_pass http://xx.xx.xx.xxx:8080;
}
}
I have an nginx sites-enabled/default configuration:
server {
listen 80;
server_name localhost;
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;
}
location ~ /anotherroute {
alias /home/anotherroute/public;
index index.html;
}
}
When I access http://myipaddress/anotherroute it works fine but when I do http://myipaddress/anotherroute/yetanotherroute it comes back as 403 forbidden.
How can I fix this?
Possibly your folder yetanotherroute is existed, make sure you have files index.php or index.html already
Otherwise you should specified a file name such as: http://myipaddress/anotherroute/yetanotherroute/somefile.php