I am trying to change those Apache rewrite rules to Nginx, but auto converter fails. And I am not very good at them. Can anyone help please?
RewriteEngine On RewriteBase / RewriteCond %{HTTP:X-HTTPS} !1 RewriteCond %{REQUEST_URI} !^/exchange_1С_Opencart.php$ RewriteCond %{REQUEST_URI} !^/TEMP$ RewriteRule ^(.)$ https://%{HTTP_HOST}/$1 [R=301,L] RewriteCond %{HTTP:X-HTTPS} 1 [NC] RewriteCond %{REQUEST_URI} ^/exchange_1С_Opencart.php$ RewriteCond %{REQUEST_URI} ^/TEMP$ RewriteRule ^(.)$ http://%{HTTP_HOST}/$1 [R=301,L] 2 variant
RewriteEngine On RewriteBase / RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} !^/exchange_1С_Opencart.php$ [NC] RewriteCond %{REQUEST_URI} !^/TEMP$ [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA] RewriteCond %{SERVER_PORT} 443 RewriteRule ^(/exchange_1С_Opencart.php)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA] RewriteRule ^(/TEMP)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA]
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!
Accepted Answer
@mianofv Wow, that’s a difficult config to read - specially if you’re new to Nginx, so I understand why you can’t figure it out.
Instead of trying to hack around with http vs https, maybe we should simply look at exchange_1С_Opencart.php
file and see why it doesn’t work with https (because it should work without any problems, since you’re already redirecting http to https).
Can you contact the developer to get it fixed?
Otherwise, you need to not use the CentMinMod wizard anymore, since it might overwrite some of the changes you’re going to make.
It’s a little difficult to figure out the configuration, since there’s so many includes.
This might work - but it might “explode”, so make a copy of domain.com.ssl.conf
before replacing with this.
Remember to replace all the domain.com
with the correct domain.
server {
server_name domain.com www.domain.com;
root /home/nginx/domains/domain.com/public;
access_log /home/nginx/domains/domain.com/log/access.log combined buffer=256k flush=60m;
error_log /home/nginx/domains/domain.com/log/error.log;
location = /exchange_1С_Opencart.php {
include /usr/local/nginx/conf/php.conf;
break;
}
location = /TEMP {
include /usr/local/nginx/conf/staticfiles.conf;
break;
}
location / {
return 302 https://$server_name/$request_uri;
}
}
server {
listen 443 ssl http2;
server_name domain.com www.domain.com;
root /home/nginx/domains/domain.com/public;
access_log /home/nginx/domains/domain.com/log/access.log combined buffer=256k flush=60m;
error_log /home/nginx/domains/domain.com/log/error.log;
ssl_dhparam /usr/local/nginx/conf/ssl/domain.com/dhparam.pem;
ssl_certificate /usr/local/nginx/conf/ssl/domain.com/domain.com-acme.cer;
ssl_certificate_key /usr/local/nginx/conf/ssl/domain.com/domain.com-acme.key;
include /usr/local/nginx/conf/ssl_include.conf;
http2_max_field_size 16k;
http2_max_header_size 32k;
ssl_ciphers EECDH+CHACHA20-draft:EECDH+CHACHA20:EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA256:EECDH+ECDSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA+SHA384:EECDH+AES128:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!CAMELLIA;
ssl_prefer_server_ciphers on;
ssl_buffer_size 1369;
ssl_session_tickets on;
resolver 8.8.8.8 8.8.4.4 valid=10m;
resolver_timeout 10s;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /usr/local/nginx/conf/ssl/domain.com/domain.com-acme.cer;
location = /exchange_1С_Opencart.php {
return 302 http://$server_name/$request_uri;
}
location = /TEMP {
return 302 http://$server_name/$request_uri;
}
location ~* \.(ttf|ttc|otf|eot|woff|woff2|font.css|css)$ {
add_header Access-Control-Allow-Origin *;
}
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
include /usr/local/nginx/conf/vts_server.conf;
}
Are you’ve change the configuration, then you need to test the config and restart Nginx:
sudo nginx -s configtest
sudo nginx -s restart
Since basic formatting tends to distort code, would you mind reposting those in a code block? You can do this by using the </> icon in the editor. Using a code block ensures proper formatting remains and we can then take a look at the rules.
Thanks! Module is connecting. But not uploading the files… I guess only a developer of that module can fix that.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.