server { listen 80; listen [::]:80; server_name www.domain.com.br; return 301 http://www.domain.com.br$request_uri;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location /sistema/ { //RUNNING NODEJS RIGHT HERE
proxy_read_timeout 600;
client_max_body_size 500M;
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
} }
I would like to serve my static files or my uploaded files from my NODEJS System through www.mydomain.com.br/sistema/uploads/path/tofile www.mydomain.com.br/sistema/views/path/to/views I am using express.static(__dirname + ‘/public’); as static folder;
Is there a possibility? I have been trying to set my server blocks, but I get 404 nginx using those url’s above.
Thank you,
Enrico Alvarenga
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
@marketingcrescimentum
Since the formatting seems to have been chopped up a little bit, can you confirm that this is identical to your server block?
If so, to start, this line should be removed:
Why? You’re already handling requests at
www.domain.com.br
by setting upserver_name
to do the same. The line above would be effective if you setup a second server block which handled redirecting requests fromdomain.com.br
towww.domain.com.br
, though inside the server block you’ve posted, it will simply create issues.To setup the server block to handle redirects, simply add the following above your existing block (still removing that line from the larger server block – it’s not needed). Now when a requests comes in without the
www
it’ll be redirected to your domain and enforce thewww
.As for the directories, let’s break things down a little so I understand the structure you’re laying out.
In the server block above, you’re defining your root directory as
/var/www/html
– Is that the location of your WordPress installation?If so, what is the physical location of your NodeJS application? Would that be:
or
or another directory? What I need to help you get everything sorted is the full path to each directory you’re using for each so I can help you make sure the correct routes are setup.