My nginx.conf contains this:
server {
listen 80;
server_name myserver.com X.X.X.X;
root /var/www/html;
location / {
proxy_pass http://127.0.0.1:8082;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_buffering off;
proxy_connect_timeout 43200000;
proxy_send_timeout 43200000;
proxy_read_timeout 43200000;
proxy_redirect off;
proxy_set_header Proxy "";
}
location /api/socket {
proxy_pass http://localhost:8082/api/socket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /newapp {
#Should this be empty?
}
}
As you can see, both / and /api/socket point to a proxy. Both of them work.
Originally this line didn't exist:
root /var/www/html;
I added it. I also added the "location /newapp". What I want is to go to the index file under the folder /var/www/html when I type
myserver.com/newapp
However, I get a 404. Am I missing something in the config file?
If you would like the URI /newapp (or /newapp/index.html) to find the file /var/www/html/index.html, you will need to use the alias directive and not the root directive.
For example:
location /newapp {
alias /var/www/html;
}
See this document for more.
Creating the folder /newapp inside /var/www/html solves the issue. But I am not sure if this is the way to go. However, it worked then.
Related
I am trying to host an API and corresponding static web app on my raspberrypi. It will only be accessible via the local network. This is the config file:
server {
listen 80;
server_name api.raspberrypi;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 80;
server_name raspberrypi;
location / {
root /Development/UI/wwwroot;
try_files $uri $uri/ /index.html =404;
}
}
Depending on where I put the prefix (api. or ui.) this part becomes inaccessible while the other one is available in the local network at http://raspberrypi:80. I would like to have the api at http://api.raspberrypi. How can this be achieved?
I have the following configuration on Nginx 1.20.1, whenever I try to access test.xxx.com/something/ I get a 404 error. I know there are other similar questions but I already have the / at the end of the proxy_pass so I have no idea what to do. The strange thing is that I have 20 other servers on that configuration, they are all identical but only this one doesn't work. Any idea?
upstream test {
server x.x.x.x:8443;
}
server {
listen 8090;
server_name test.xxx.com;
root /var/www/vhosts/test.xxx.com/;
location / {
access_log /var/log/nginx/access_test.log upstreamlog;
proxy_pass https://test/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 75s;
proxy_send_timeout 1800s;
proxy_read_timeout 1800s;
}
}
I have nginx reverse proxy
server {
listen 80;
server_name $APP_DOMAIN;
try_files $uri/index.html $uri.html #backend #frontend #selenoid;
location /seltest/ {
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_max_temp_file_size 0;
rewrite ^/seltest/(.*)$ /$1 break;
proxy_pass http://selenoid_application_server/;
}
...
when I go to /seltest I got You need to enable JavaScript to run this app.
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
502 bad gateway error, hmm I've no problem with my dns. I have a folder named 'app' and 'website' in my /home directory.
server {
listen 80;
server_name dashboard.abc.com;
location / {
root app;
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;
}
}
server {
listen 80;
server_name abc.com
location / {
root site;
index index.html index.htm;
}
}
Everything make sense here, not sure which part is causing the problem