Post by HAO » Fri Jul 30, 2021 7:21 pm

Requirements
These are minimum requirements needed so that OpenCart can be installed and work properly.

Web Server (Apache suggested)
PHP (at least 5.4)
Curl enabled
Database (MySQLi suggested)

I know this is the official installation suggestion of OpenCart, But based on the request of my boss, we still choose Nginx -Tengine 2.2.4 (2.3.2) as our HTTP server.

But when I can’t use the .htaccess file to make my module fully compatible, I want to know how to achieve my needs in Nginx -Tengine 2.2.4 (2.3.2), Can anyone advise on the .htaccess file I used before?

Thank you!

Our .htaccess file:

Code: Select all

php_value log_errors on
php_value error_reporting 32767
php_value error_log /home/user/public_html/error_log
#Added by Red from TWNOC 2019-04-11
RewriteEngine On
RewriteBase /
SetEnvIfNoCase User-Agent "SemrushBot" bots
SetEnvIfNoCase User-Agent "AhrefsBot" bots
Deny from env=bots
#End of added

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

Options +FollowSymlinks

# Prevent Directoy listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
 Require all denied
## For apache 2.2 and older, replace "Require all denied" with these two lines :
# Order deny,allow
# Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/download/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# PREVENT SQL INJECTION IN QUERY STRING
RewriteCond %{REQUEST_FILENAME}   !sql_attack_protection\.php
RewriteCond %{QUERY_STRING}   information_schema
RewriteRule  ^(.*?)          /sql_attack_protection.php [R=301,L]

<Files 403.shtml>
order allow,deny
allow from all
</Files>

### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE image/x-icon
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript

    #DeflateCompressionLevel 9

    # Browser specific settings
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    BrowserMatch \bOpera !no-gzip

    # Setup custom deflate log
    #DeflateFilterNote Input instream
    #DeflateFilterNote Output outstream
    #DeflateFilterNote Ratio ratio

    #LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%)' deflate
    # Example of log file
    #CustomLog logs/deflate_log DEFLATE
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ############################################
    ## Add default Expires header
    ## developer.yahoo.com/performance/rules.html
    <FilesMatch "\.(ico|pdf|flv|jpg|JPG|jpeg|png|gif|js|css|swf|woff|svg)$">
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
</IfModule>

<ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

RewriteEngine On 
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR] 
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR] 
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR] 
RewriteRule ^.* - [F,L]

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.pcstore.com.tw/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.pcstore.com.tw/$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

<Files "xmlrpc.php">
Order Allow,Deny
deny from all
</Files>

<Files 403.shtml>
order allow,deny
allow from all
</Files>
How can we modify the rules for Nginx to meet our needs, And how to start?

Can anyone tell me? If anyone can tell me, I will be very grateful for this, Thank you in advance for your help!

Thank you!

HAO
Active Member

Posts

Joined
Fri Jun 03, 2011 2:52 pm

Post by paulfeakins » Fri Jul 30, 2021 7:40 pm

You'll need to identify which of your custom changes don't work and then find the correct way to apply those in Nginx.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by HAO » Fri Jul 30, 2021 8:01 pm

Basically I am completely unfamiliar with Nginx, I do not even know how to replace the use of .htaccess file in the way, I think I need to understand how to set the code in .htaccess in Nginx.

How can I start correctly if Nginx can run .htaccess?

Thank you!
--------------

I found a website that can convert content between Apache and Nginx, But i'm not sure what i lost.

Can someone tell me what I successfully converted and what I lost?

Code: Select all

# nginx configuration by winginx.com

autoindex off;

location ~ .*\.(ico|gif|jpg|jpeg|png|js|css) {
}

deny env=bots;

autoindex off;

location = /sitemap.xml {
  rewrite ^(.*)$ /index.php?route=extension/feed/google_sitemap break;
}

location = /googlebase.xml {
  rewrite ^(.*)$ /index.php?route=extension/feed/google_base break;
}

location /system {
  rewrite ^/system/download/(.*) /index.php?route=error/not_found break;
}

location / {
  if (!-e $request_filename){
    rewrite ^/([^?]*) /index.php?_route_=$1 break;
  }
  rewrite ^(.*)$ https://$http_host$request_uri redirect;
  if ($query_string ~ "information_schema"){
    rewrite ^/(.*?) /sql_attack_protection.php redirect;
  }
  if ($http_user_agent ~ "^BlackWidow"){
    return 403;
  }
  if ($http_user_agent ~ "^Bot\ mailto:craftbot@yahoo.com"){
    return 403;
  }
  if ($http_user_agent ~ "^ChinaClaw"){
    return 403;
  }
  if ($http_referer !~ "^$"){
    return 403;
  }
}

location /403.shtml {
  allow all;
  allow all;
}

location /xmlrpc.php {
  deny all;
}
Thank you!

HAO
Active Member

Posts

Joined
Fri Jun 03, 2011 2:52 pm

Post by paulfeakins » Mon Aug 02, 2021 6:27 pm

We have sites that use Nginx and use standard .htaccess files, so something's a bit odd there.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by glolar » Tue Nov 16, 2021 2:19 am

paulfeakins wrote:
Mon Aug 02, 2021 6:27 pm
We have sites that use Nginx and use standard .htaccess files, so something's a bit odd there.
Hi Paul, can you please elaborate on how you are able to get OpenCart to work with NGINX? When I enable NGINX at my web host (SiteGround), I get CORS errors when my sites trie to download fontawesome fonts (among other things) that my themes use. For this reason, for my four different OC stores (one is OC 3.0.3.8, the other three are 3.0.2.0), I have to disable NGINX on the server.

Any help is appreciated!

User avatar
Active Member

Posts

Joined
Thu Jul 29, 2010 12:35 pm
Location - San Diego, CA
Who is online

Users browsing this forum: No registered users and 66 guests