Setting up a new server with CentOS 7 and LAMP, but I have few questions.

I will be setting up a new server soon and I have few questions.

I will be installing CentOS 7 with LAMP stack, but I also heard that I can install Nginx as reverse proxy.

  1. Is this possible and if it is, is it smart to do that?
  2. Later I will be installing Node.js app (or probably MEAN stack), I just want to make sure it will function correctly with setup above?
  3. And lastly will I be able to install other applications normally without configuring them additionally due to reverse proxy.

I am new with nginx and node.js, but I am familiar with DO, ubuntu, LAMP stack and basic beginner stuff.

Thank you for answering.

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


Honestly, I can’t really think of a situation where NGINX wouldn’t be a good fit :-). While Apache can do some of the same things as NGINX, I find the syntax a bit cluttered and dated.

For me, as a developer/programmer, I find the syntax of NGINX to be far cleaner.

As a basic example, the typical VirtualHost block for Apache looks something like:

<VirtualHost *:80>

    DocumentRoot /var/www/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /path/to/dir>


Some will argue that’s pretty clean, though with NGINX, the above would look like:

server {
    listen 80;
    listen [::]:80;

    access_log /path/to/;
    error_log /path/to/;

    root /path/to/home/dir;

    location / {
        try_files $uri $uri/ /index.php?$args;

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_index index.php;

        include fastcgi_params;

The above is a simple server block to handle WordPress sites. Comparing the two, the syntax of NGINX is much like a programming language, so without any other considerations, I naturally draw to it.

Beyond the programming-like syntax, it’s super simple to setup Proxying. For example, if we wanted to proxy a NodeJS application, our server block would look something like:

upstream @backend {

    listen 80;
    listen [::]:80;
    server_name _;

    location /
        proxy_pass http://@backend;

        proxy_buffers 16 32k;
        proxy_buffer_size 64k;
        proxy_busy_buffers_size 128k;
        proxy_cache_bypass $http_pragma $http_authorization;
        proxy_connect_timeout 59s;
        proxy_hide_header X-Powered-By;
        proxy_http_version 1.1;
        proxy_ignore_headers Cache-Control Expires;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
        proxy_no_cache $http_pragma $http_authorization;
        proxy_pass_header Set-Cookie;
        proxy_read_timeout 600;
        proxy_redirect off;
        proxy_send_timeout 600;
        proxy_set_header Accept-Encoding '';
        proxy_set_header Cookie $http_cookie;
        proxy_set_header Host $host;
        proxy_set_header Referer $http_referer;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_temp_file_write_size 64k;
        proxy_set_header X-Original-Request $request_uri;

Now I know that looks complex, though that’s working configuration. You’d need to change the port in @backend at the top to match your NodeJS application port, and server_name to match your domain, but that will just work 99% of the time.

Beyond that, if you wanted to do something really crazy, you could load balance, proxy an application, serve multiple WordPress sites, and cache all with the same NGINX server. It’s not ideal, but you can. NGINX functions as a reverse proxy, load balancer, PHP-FPM proxy, caching proxy, etc.

The repo that I noted in the above post sets up a fully configured NGINX installation from source with numerous example configurations that work.

The configuration is already tweaked/tuned for production use and works well (I used it on many sites).

As far as recommendations, I would start with at least 1GB RAM, though 2GB would be preferred. That’s not because NGINX is RAM-hungry, it’s because MySQL/MariaDB and WordPress + NodeJS applications are from time to time.

You need RAM to run NGINX, PHP-FPM, MySQL/MariaDB, and NodeJS on the same server, and without a good amount, services crash.

The good news is that in those installers, there’s a also installers for MariaDB (a MySQL fork that has better overall performance), PHP-FPM (5.6, 7.0, and 7.1), as well as NodeJS.

So you could run the installers and easily setup each piece of software with relative ease :-).

@hansen @jtittle


thank you for quick replies, I am confused what is real advantage of nginx over apache.

I know its faster, but I’ve read somewhere that it is not for dynamic sites. Can you give me example of sites that are good for nginx and type of site that are not for nginx.

Mine will be worpdress site with node.js web-app on a sub-domain.

Also I forgot to ask on a original thread how powerful droplet should I choose? Is $5 enough or $10 is smart choice?

@Chempo @hansen

Completely agree on selecting NGINX over Apache or NGINX + Apache. Unless you’re locked to Apache, for one reason or another (I can’t think of anything specific off the top of my head), then choosing NGINX from the start would be the best option.

You can run a normal PHP site with one server block and proxy requests to a NodeJS application with another server block with relative ease.

If you were using Ubuntu 16.04, I’d recommend using the auto-installer I wrote to compile NGINX from source. It’ll setup a pretty well optimized NGINX configuration and all you need to do is:

cd /opt \
&& git clone \
&& cd installers/nginx \
&& chmod +x \
&& ./

That’ll setup the latest version of NGINX complete with Brotli compression support as well as quite a few examples to get you started ranging from NGINX as a Load Balancer, NGINX as a Proxy (for your NodeJS app), PHP-FPM, etc.

I’m actually reworking the script now as the one there needs a little more TLC, in my opinion, but it works well enough as-is.

Of course, if you choose to go Ubuntu and use that, if you have any questions feel free to ask.