Skip to content

4. Web Server

Indra Lukmana edited this page Jul 14, 2017 · 2 revisions

Configuring Web Server

This web application has been tested in Nginx web server with the following configurations. It is possible to run the node web application and configure it using Apache web server but it has not been tested for this application yet.

Nginx

The basic configuration for Nginx is as follows

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  localhost test.polyanno.librarylabs.ed.ac.uk;
    root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
        proxy_pass http://localhost:7777;
        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;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

}

This setting can be set in nginx configuration. In CentOS operating system environment this configuration can be opened using this command

sudo rvim /etc/nginx/conf.d/default.conf

To edit the SSL configuration the file to be edited is the ssl.conf, in CentOS operating system environment this can be done using this command

sudo rvim /etc/nginx/conf.d/ssl.conf

The basic configuration for the ssl.conf as follow

server {
    listen       443 ssl http2 default_server;
    listen       [::]:443 ssl;
    server_name  localhost test.polyanno.librarylabs.ed.ac.uk;
    root         /usr/share/nginx/html;

    ssl_certificate /home/lacddt/certs/test.polyanno.librarylabs.ed.ac.uk.crt;
    ssl_certificate_key /home/lacddt/certs/test.polyanno.librarylabs.ed.ac.uk.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
        proxy_pass http://localhost:7777;
        proxy_redirect off;

        proxy_set_header Host $http_host ;
        proxy_set_header X-Real-IP $remote_addr ;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
        proxy_set_header X-Forwarded-Proto https;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

To run the Nginx web server as service run this command with root privilage

sudo service nginx start

If you configure the settings in .conf folder then you need to restart the service using this

sudo service nginx restart

Apache

It should be possible to run the application with Apache web server. The basic configuration will be as follows (it still has not been tested with this application)

<VirtualHost *:80>
    ServerAdmin admin@site.com
    ServerName test.site.com
    ServerAlias www.site.com 

    ProxyRequests off

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    <Location /path/of/my/project>
            ProxyPass http://localhost:7777/
            ProxyPassReverse http://localhost:7777/
    </Location>
</VirtualHost>

If you want to run using Apache then set the servername, url, and directory accordingly.

Clone this wiki locally