I have a ghost.org pre-built droplet on DigitalOcean that I'm willing to use for a music production blog. This is what my site conf looks like:
server {
listen 80;
listen [::]:80;
server_name mydomain.com;
root /var/www/ghost/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2369;
}
location ~ /.well-known {
allow all;
}
client_max_body_size 50m;
}
I want to serve some html pages I uploaded at this directory /var/www/downloads when people visits my domain.com/downloads. How do I do it leaving everything else working? I've tried this
location /downloads/ {
alias /var/www/downloads/;
}
but it did not work. Any help?
Thanks!
Try this:
location /downloads {
root /var/www;
}
Related
I'm really new to NGINX.
Currently, I have a containerized app (PHP Application) in my server; and it is can be viewed via 192.168.1.20:8080 (ip address is just an example). The app is perfectly fine.
But, I want my app to be able to viewed via 'my-domain-name.com/my-app'. Can I achieve this? I've searched for the solutions and a lot of them are using subdomains instead.
I've also tried below configurations under /etc/nginx/sites-available/my-app. But none of them works.
server {
listen 80;
listen [::]:80;
server_name my-domain-name.com/my-app;
location / {
proxy_pass http://192.168.1.20:8080;
}
}
server {
root /var/www/html;
listen 80;
listen [::]:80;
server_name my-domain-name.com/my-app www.my-domain-name.com/my-app;
location / {
proxy_pass http://192.168.1.20:8080;
proxy_redirect off;
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-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server_name property requires a domain name and does not support subdirectories.
You can specify your path in location property:
server {
listen 80;
listen [::]:80;
server_name my-domain-name.com;
location /my-app {
proxy_pass http://192.168.1.20:8080;
}
}
(source: nginx docs)
I am just posting this here as an answer to a question I had for a fairly nuanced problem.
I have two servers (two different machines):
backend.website.com
www.website.com
Some static files are hosted in a directory called /audiofiles, these need to be accessible at www.website.com/audiofiles, but are stored on the machine for backend.website.com. Yes, this is a convoluted requirement, but it is the case in our situation and cannot be changed.
My answer below is how we accomplished this.
Here is the config that let us accomplish this:
backend.website.com:
server {
listen 80;
server_name backend.website.com;
root /var/www/backend/;
index index.html index.htm index.php;
location ^~ /audiofiles/ {
alias /some/other/folder/audiofiles/;
autoindex on;
break;
}
# ... other stuff
}
www.website.com
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name website.com www.website.com;
location /audiofiles/ {
proxy_pass https://backend.website.com;
proxy_redirect /audiofiles/ https://www.website.com/audiofiles/;
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-Proto https;
}
# ... other stuff
}
I have two websites, ineedbabypics.com and ineedtoclose.com
I have updated both domain names A record to point to my public IP address.
The problem is I followed various online settings for proxy and can't get the simple redirect to work. When I type in both domain names in my browser, it both goes to ineedbabypics.com.
I want ineedbabypics.com to go to 192.168.1.96 and ineedtoclose.com to go to 192.168.1.83. Here are my server block settings:
#nginx.conf
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
#ineedbabypics.conf
server {
server_name http://ineedbabypics.com www.ineedbabypics.com;
set $upstream 192.168.1.96;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://$upstream;
}
}
#ineedtoclose.conf
server {
server_name http://ineedtoclose.com www.ineedtoclose.com;
set $upstream 192.168.1.83;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://$upstream;
}
}
I have the following Nginx server block:
server {
listen 80;
listen [::]:80;
server_name example.com;
root /usr/share/nginx/html;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://localhost/page-1/;
}
}
I would like that when the user gets a 404 error on example.com, the proxy_pass should change to direct to http://localhost/example-404/.
However, this server block and the one for http://localhost both have the same root so alternatively it could just point to /example-404/ internally, I'm not sure which is easier to do. Either way, I want the address in the browser's address bar to stay the same.
The reason I want this is that there will be a different 404 page if accessing the server from http://localhost directly. I would really appreciate anyone's thoughts on this!
You can use different vhosts to give different results depending on how the user is accessing the server. I'd imagine something like this might work:
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_intercept_errors on;
error_page 404 = #errors;
proxy_pass http://localhost/page-1/;
}
location #errors {
root /usr/share/nginx/errors/example.com.404.html;
}
}
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_intercept_errors on;
error_page 404 = #errors;
proxy_pass http://localhost/page-1/;
}
location #errors {
root /usr/share/nginx/errors/localhost.404.html;
}
}
Can someone help me configure my nginx where:
/app -> is the local html pages
/ -> is the https server which does not have app folder
The following conf didnt work for me: (
server {
listen 80;
ssl_verify_client off;
server_name localhost;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass https://xx.xx.xx.xx/;
}
location /app {
root "c:\LOCAL_PATH\app";
index index.html;
}
}
Exhanging your location /-block for the following oughta do it:
location / { rewrite ^ https://$host$request_uri?; }