The best way is to use the nginx server to serve the static file and let the node.js server handle dynamic content.
This is usually the most optimized solution to reduce the number of requests on your node.js server, which is slower than the static server files than nginx, for example:
The configuration to achieve this goal is very simple if you have already installed the reverse proxy for the nodejs application.
Configuration
nd nginx could be
root /home/myapp; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name _; location /public/ { alias /home/myapp/public/; } location / { proxy_pass http:
Each request from / public / in the first part of the URL will be processed by nginx, and each other request will be proxied to you by the IPADRESSOFNODEJSSERVER:NODEJSPORT application in your IPADRESSOFNODEJSSERVER:NODEJSPORT , usually IPADRESSOFNODEJSSERVER is localhost
The expression doc section says that http://expressjs.com/en/advanced/best-practice-performance.html#proxy
An even better option is to use a reverse proxy to serve static files; see Using reverse proxy for more information.
In addition, nginx will allow you to easily define caching rules, so for static assets that do not change, this can speed up your application with one line.
location /public/ { expires 10d; alias /home/myapp/public/; }
You can find many articles that compare both methods on the Internet, for example: http://blog.modulus.io/supercharge-your-nodejs-applications-with-nginx
Aaleks
source share