ScaleScaleScaleScale

Tips / Nginx


Nginx configuration for OsCommerce

OsCommerce is a very popular software used to build e-commerce stores. This free shopping cart is available in many languages and has a large community of users that have built more than 7000 plugins/addons to extend the basic features of OsCommerce.

With OsCommerce you can setup your own online store, create, edit and delete products, set pricing, collect taxes and setup payment gateways like Paypal, 2checkout, iPayment, Authorize.net and many others. From the users side, customers can view their order history, edit details of their accounts and get in touch with the store owner if they had a problem. OsCommerce allows you to change the look of your online store by using hundred of free templates that you can customize at any time.

OsCommerce Requirements

osCommerce Online Merchant can run on almost any kind of server that has PHP & MySQL installed. According to their webpage official software version requirements are:

  • PHP v4+ (v5+ recommended)
  • MySQL v3+ (v5+ recommended)

Fore more information about PHP functions requirements, make sure you read this document

Configurig OsCommerce on Nginx powered servers

We will assume you already have Nginx installed and running on your server, same as PHP-FPM the daemon that will process all the dynamic process. If not, please follow this links to get started about installing Nginx:

Installing php-fpm on the other side is pretty easy. Login as root and type:

If you are running CentOS:

yum install php-fpm
chkconfig php-fpm on
servic php-fpm start

If you are running Ubuntu:

apt-get install php5-fpm
/etc/init.d/php5-fpm start
update-rc.d php5-fpm defaults

Nginx configuration for OsCommerce Online Stores

OsCommerce does not require any special configuration to work, we will only deny access to some dangerous directory often attacked by script kiddies, and also set static cache for files, images and css files.

Edit nginx.conf or your virtual host configuration file and add this under the server {} block configuration.

### OsCommerce configuration

# Deny access to this directories
location ~ ^/includes/.*\.php$ { return 403; }
location ~ ^/admin/includes/.*\.php$ { return 403; }
location ^~ /admin/backups { return 403; }
location ^~ /download { return 403; }

# Set max cache for static stuff
location /catalog { expires max; }

### End OsCommerce configuration

Afert that, reload your Nginx to apply changes:

service nginx reload

This is a full example of OsCommerce running with Nginx and PHP-FPM daemon:

## yoursite.com

server {

access_log logs/access_log;
error_log logs/error_log crit;
log_not_found off;

listen 80;
server_name yoursite.com www.yoursitecom;
root /var/www/yoursite.com;
index index.php index.html index.htm;

### OsCommerce configuration

# Deny access to this directories
location ~ ^/includes/.*\.php$ { return 403; }
location ~ ^/admin/includes/.*\.php$ { return 403; }
location ^~ /admin/backups { return 403; }
location ^~ /download { return 403; }

# Set max cache for static stuff
location /catalog { expires max; }

### End OsCommerce configuration

# PHP-FPM configuration
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}

With this configuration you should be able to mount your OsCommerce solution without any problems. We haven’t included any rewrite rules for SEO Friendly URLs because in the latest version (2.4.x) there is no native OsCommerce module for SEO URLs, and you have to choose one of the available SEO modules for OsCommerce if you need to rewrite your URLs.

Conclusion

As we’ve seen, OsCommerce is one of the leading e-commerce solutions for people who want to mount their online store with a stable and fast solution. At this time, you should have your Oscommerce configured and working on Nginx web server, which will help you to boost your site speed and as we all know, site speed is one of the key factors to boost your sales conversions. Remember to also include an SSL certificate for your website to secure your online transactions, check out this tutorial for more information: How to install a SSL certificate on Nginx

Popular search terms:

  • nginx oscommerce
  • built ecommerce with nginx
  • nginx for ecommerce
  • online nginx configuration
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking