简体   繁体   中英

Converting Apache Mod Rewrite rules to NGINX

I am currently hosting a copy of ShoutCast Manager, so that people can stream audio and configure their streams using a web interface.

I am using Apache 2.4 web server as the HTTP server and it seems to have an issue with handling large upload files. I've edited my Apache configuration to allow the upload of larger files, as well as increased the timeout limit. PHP has also been given an increased timeout limit, as well as an increased memory limit of 512MiB.

When uploading audio files with sizes in excess of 200MiB, the server responds with "Service Unavailable" and the file upload doesn't complete.

As such, I wish to move to NGINX as my web server solution and I am having issues with converting my rewrite rules to ones that work with NGINX. The rules I am currently using with Apache are as follows:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

# Rewrites
RewriteRule ^view/([0-9]+)/([0-9]+)/([^/]*)$ ./viewserver.php?portbase=$1&id=$2&srvname=$3 [L,QSA]
RewriteRule ^view/([0-9]+)/([0-9]+)/([^/]*)/$ ./viewserver.php?portbase=$1&id=$2&srvname=$3 [L,QSA]
RewriteRule ^start/([0-9]+)/([0-9]+)/([^/]*)$ ./control.php?control=$1&id=$2&action=start&srvname=$3 [L,QSA]
RewriteRule ^start/([0-9]+)/([0-9]+)/([^/]*)/$ ./control.php?control=$1&id=$2&action=start&srvname=$3 [L,QSA]
RewriteRule ^stop/([0-9]+)/([0-9]+)/([^/]*)$ ./control.php?control=$1&id=$2&action=stop&srvname=$3 [L,QSA]
RewriteRule ^stop/([0-9]+)/([0-9]+)/([^/]*)/$ ./control.php?control=$1&id=$2&action=stop&srvname=$3 [L,QSA]
RewriteRule ^restart/([0-9]+)/([0-9]+)/([^/]*)$ ./control.php?control=$1&id=$2&action=restart&srvname=$3 [L,QSA]
RewriteRule ^restart/([0-9]+)/([0-9]+)/([^/]*)/$ ./control.php?control=$1&id=$2&action=restart&srvname=$3 [L,QSA]
RewriteRule ^edit/([0-9]+)/([0-9]+)/([^/]*)$ ./edit.php?portbase=$1&id=$2&status=$3 [L,QSA]
RewriteRule ^edit/([0-9]+)/([0-9]+)/([^/]*)/$ ./edit.php?portbase=$1&id=$2&status=$3 [L,QSA]
RewriteRule ^delete/([0-9]+)/([0-9]+)/([^/]*)$ ./delete.php?id=$1&port=$2&srvname=$3 [L,QSA]
RewriteRule ^delete/([0-9]+)/([0-9]+)/([^/]*)/$ ./delete.php?id=$1&port=$2&srvname=$3 [L,QSA]
RewriteRule ^widgets/([^/]*)/([^/]*)\.js$ ./include/widgets.js.php?port=$1&type=$2 [L,QSA]
RewriteRule ^public/api/autodj/([^/]*)/([^/]*)/([^/]*)$ ./api/api.controller/index.php?api-key=$1&port=$2&action=autodj&autodj=$3 [L,QSA]
RewriteRule ^public/api/autodj/([^/]*)/([^/]*)/([^/]*)/$ ./api/api.controller/index.php?api-key=$1&port=$2&action=autodj&autodj=$3 [L,QSA]
RewriteRule ^public/api/server/([^/]*)/([^/]*)/([^/]*)$ ./api/api.controller/index.php?api-key=$1&port=$2&action=$3 [L,QSA]
RewriteRule ^public/api/server/([^/]*)/([^/]*)/([^/]*)/$ ./api/api.controller/index.php?api-key=$1&port=$2&action=$3 [L,QSA]
RewriteRule ^public/api/schedule/([^/]*)/([^/]*)/([^/]*)$ ./api/api.controller/index.php?api-key=$1&port=$2&action=schedule&schedule=$3 [L,QSA]
RewriteRule ^public/api/schedule/([^/]*)/([^/]*)/([^/]*)/$ ./api/api.controller/index.php?api-key=$1&port=$2&action=schedule&schedule=$3 [L,QSA]
RewriteRule ^download-playlist/([0-9]+).([^/]*)$ ./include/widgets/playlists/playlists.php?port=$1&type=$2 [L,QSA]
RewriteRule ^events/([^/]*)/$ ./eventlog.php?log=$1 [L,QSA]
RewriteRule ^events/([^/]*)/([^/]*)/$ ./eventlog.php?log=$1&page=$2 [L,QSA]

# Errors
RewriteRule ^errors/404/$ ./404.php [L,QSA]
ErrorDocument 404 /errors/404/

RewriteRule ^errors/403/$ ./404.php [L,QSA]
ErrorDocument 403 /errors/403/

RewriteRule ^errors/500/$ ./500.php [L,QSA]
ErrorDocument 500 /errors/500/

A copy of ShoutCast Manager can be found here: https://github.com/gaza1994/SHOUTcast-Manager

Any help with making NGINX compatible rewrite rules would be super appreciated!

This is untested, but this should do the trick

error_page 500 /errors/500/;    
error_page 404 /errors/404/;    
error_page 403 /errors/403/;

rewrite ^/view/([0-9]+)/([0-9]+)/([^/]*)$ /viewserver.php?portbase=$1&id=$2&srvname=$3 last;
rewrite ^/view/([0-9]+)/([0-9]+)/([^/]*)/$ /viewserver.php?portbase=$1&id=$2&srvname=$3 last;
rewrite ^/start/([0-9]+)/([0-9]+)/([^/]*)$ /control.php?control=$1&id=$2&action=start&srvname=$3 last;
rewrite ^/start/([0-9]+)/([0-9]+)/([^/]*)/$ /control.php?control=$1&id=$2&action=start&srvname=$3 last; 
rewrite ^/stop/([0-9]+)/([0-9]+)/([^/]*)$ /control.php?control=$1&id=$2&action=stop&srvname=$3 last;
rewrite ^/stop/([0-9]+)/([0-9]+)/([^/]*)/$ /control.php?control=$1&id=$2&action=stop&srvname=$3 last;
rewrite ^/restart/([0-9]+)/([0-9]+)/([^/]*)$ /control.php?control=$1&id=$2&action=restart&srvname=$3 last;
rewrite ^/restart/([0-9]+)/([0-9]+)/([^/]*)/$ /control.php?control=$1&id=$2&action=restart&srvname=$3 last;
rewrite ^/edit/([0-9]+)/([0-9]+)/([^/]*)$ /edit.php?portbase=$1&id=$2&status=$3 last;
rewrite ^/edit/([0-9]+)/([0-9]+)/([^/]*)/$ /edit.php?portbase=$1&id=$2&status=$3 last;
rewrite ^/delete/([0-9]+)/([0-9]+)/([^/]*)$ /delete.php?id=$1&port=$2&srvname=$3 last;
rewrite ^/delete/([0-9]+)/([0-9]+)/([^/]*)/$ /delete.php?id=$1&port=$2&srvname=$3 last;
rewrite ^/widgets/([^/]*)/([^/]*)\.js$ /include/widgets.js.php?port=$1&type=$2 last;
rewrite ^/public/api/autodj/([^/]*)/([^/]*)/([^/]*)$ /api/api.controller/index.php?api-key=$1&port=$2&action=autodj&autodj=$3 last;
rewrite ^/public/api/autodj/([^/]*)/([^/]*)/([^/]*)/$ /api/api.controller/index.php?api-key=$1&port=$2&action=autodj&autodj=$3 last;
rewrite ^/public/api/server/([^/]*)/([^/]*)/([^/]*)$ /api/api.controller/index.php?api-key=$1&port=$2&action=$3 last;
rewrite ^/public/api/server/([^/]*)/([^/]*)/([^/]*)/$ /api/api.controller/index.php?api-key=$1&port=$2&action=$3 last;
rewrite ^/public/api/schedule/([^/]*)/([^/]*)/([^/]*)$ /api/api.controller/index.php?api-key=$1&port=$2&action=schedule&schedule=$3 last;
rewrite ^/public/api/schedule/([^/]*)/([^/]*)/([^/]*)/$ /api/api.controller/index.php?api-key=$1&port=$2&action=schedule&schedule=$3 last;
rewrite ^/download-playlist/([0-9]+).([^/]*)$ /include/widgets/playlists/playlists.php?port=$1&type=$2 last;
rewrite ^/events/([^/]*)/$ /eventlog.php?log=$1 last;
rewrite ^/events/([^/]*)/([^/]*)/$ /eventlog.php?log=$1&page=$2 last;

SHOUTcast manager should function normally under NGINX too!

Try this tool. The tool converts an Apache's .htaccess to nginx configuration instructions. https://winginx.com/en/htaccess

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM