Dieser Artikel ist Teil einer Reihe zum Webserver nginx. Schau dir auch die anderen Artikel an: Zum Leitartikel Nach der Installation von nginx stellte ich mich der Herausforderung, alle meine Simplemachines -Foren auf Nginx umzuziehen. In einigen hatte ich das PrettyUrls -Plugin installiert, da es einerseits schöner und sprechender aussieht und andererseits durch die Suchmaschinen wohl besser akzeptiert wird. Diese wollte ich natürlich auch weiterhin nutzen. Ich fand zwar eine Seite, die schon Rewrite-Regeln anbot, jedoch waren das noch nicht ausreichend viele, da ich zusätzlich noch für alle Aktionen die schönen URLs aktiviert hatte.

Meine finalen Regeln:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
server {
 listen 80;
 server_name forum.example.com *.forum.example.com;
 error_log /var/log/nginx/forum.example.com.log warn;
 root /var/www/forum.example.com/;

 location / {
 index index.php;

 # Rules for: actions
 rewrite ^/(activate|admin|announce|ban|boardrecount|buddy|calendar|cleanperms)/?$ /index.php?pretty%3Baction=$1 last;
 rewrite ^/(collapse|convertentities|convertutf8|coppa|deletemsg|detailedversion|display|dlattach)/?$ /index.php?pretty%3Baction=$1 last;
 rewrite ^/(dumpdb|editpoll|editpoll2|featuresettings|featuresettings2|findmember|help|helpadmin)/?$ ./index.php?pretty%3Baction=$1 last;
 rewrite ^/(im|jsoption|jsmodify|lock|lockVoting|login|login2|logout)/?$ ./index.php?pretty%3Baction=$1 last;
 rewrite ^/(maintain|manageattachments|manageboards|managecalendar|managesearch|markasread|membergroups|mergetopics)/?$ ./index.php?pretty%3Baction=$1 last;
 rewrite ^/(mlist|modifycat|modifykarma|modlog|movetopic|movetopic2|news|notify)/?$ ./index.php?pretty%3Baction=$1 last;
 rewrite ^/(notifyboard|optimizetables|packageget|packages|permissions|pgdownload|pm|post)/?$ ./index.php?pretty%3Baction=$1 last;
 rewrite ^/(post2|postsettings|printpage|profile|profile2|quotefast|quickmod|quickmod2)/?$ ./index.php?pretty%3Baction=$1 last;
 rewrite ^/(recent|regcenter|register|register2|reminder|removetopic2|removeoldtopics2|removepoll)/?$ ./index.php?pretty%3Baction=$1 last;
 rewrite ^/(repairboards|reporttm|reports|requestmembers|search|search2|sendtopic|serversettings)/?$ ./index.php?pretty%3Baction=$1 last;
 rewrite ^/(serversettings2|smileys|smstats|spellcheck|splittopics|stats|sticky|theme)/?$ ./index.php?pretty%3Baction=$1 last;
 rewrite ^/(trackip|about:mozilla|about:unknown|unread|unreadreplies|viewErrorLog|viewmembers|viewprofile)/?$ ./index.php?pretty%3Baction=$1 last;
 rewrite ^/(verificationcode|vote|viewquery|who|\.xml)/?$ ./index.php?pretty%3Baction=$1 last;

 # Rules for: boards
 rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/[0-9]?/?$ /index.php?pretty%3Bboard=$1.0 last;
 rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/[0-9]?/?$ /index.php?pretty%3Bboard=$1.$2 last;

 # Rules for: topics
 rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/[0-9]?/?$ /index.php?pretty%3Bboard=$1%3Btopic=$2.0 last;
 rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/[0-9]?/?$ /index.php?pretty%3Bboard=$2%3Btopic=$2.$3 last;

 # And the sitemap
 rewrite ^sitemap.xml$ /index.php?action=sitemap%3Bxml last;
 }

 location ~ \.php$ {
 fastcgi_pass 127.0.0.1:1234;
 include /etc/nginx/fastcgi_params;
 }
}server {
        listen          80;
        server_name     forum.example.com *.forum.example.com;
        error_log       /var/log/nginx/forum.example.com.log warn;
        root            /var/www/forum.example.com/;

        location / {
                index           index.php;

                # Rules for: actions
                rewrite ^/(activate|admin|announce|ban|boardrecount|buddy|calendar|cleanperms)/?$ /index.php?pretty%3Baction=$1 last;
                rewrite ^/(collapse|convertentities|convertutf8|coppa|deletemsg|detailedversion|display|dlattach)/?$ /index.php?pretty%3Baction=$1 last;
                rewrite ^/(dumpdb|editpoll|editpoll2|featuresettings|featuresettings2|findmember|help|helpadmin)/?$ ./index.php?pretty%3Baction=$1 last;
                rewrite ^/(im|jsoption|jsmodify|lock|lockVoting|login|login2|logout)/?$ ./index.php?pretty%3Baction=$1 last;
                rewrite ^/(maintain|manageattachments|manageboards|managecalendar|managesearch|markasread|membergroups|mergetopics)/?$ ./index.php?pretty%3Baction=$1 last;
                rewrite ^/(mlist|modifycat|modifykarma|modlog|movetopic|movetopic2|news|notify)/?$ ./index.php?pretty%3Baction=$1 last;
                rewrite ^/(notifyboard|optimizetables|packageget|packages|permissions|pgdownload|pm|post)/?$ ./index.php?pretty%3Baction=$1 last;
                rewrite ^/(post2|postsettings|printpage|profile|profile2|quotefast|quickmod|quickmod2)/?$ ./index.php?pretty%3Baction=$1 last;
                rewrite ^/(recent|regcenter|register|register2|reminder|removetopic2|removeoldtopics2|removepoll)/?$ ./index.php?pretty%3Baction=$1 last;
                rewrite ^/(repairboards|reporttm|reports|requestmembers|search|search2|sendtopic|serversettings)/?$ ./index.php?pretty%3Baction=$1 last;
                rewrite ^/(serversettings2|smileys|smstats|spellcheck|splittopics|stats|sticky|theme)/?$ ./index.php?pretty%3Baction=$1 last;
                rewrite ^/(trackip|about:mozilla|about:unknown|unread|unreadreplies|viewErrorLog|viewmembers|viewprofile)/?$ ./index.php?pretty%3Baction=$1 last;
                rewrite ^/(verificationcode|vote|viewquery|who|\.xml)/?$ ./index.php?pretty%3Baction=$1 last;

                # Rules for: boards
                rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/[0-9]?/?$ /index.php?pretty%3Bboard=$1.0 last;
                rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/[0-9]?/?$ /index.php?pretty%3Bboard=$1.$2 last;

                # Rules for: topics
                rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/[0-9]?/?$ /index.php?pretty%3Bboard=$1%3Btopic=$2.0 last;
                rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/[0-9]?/?$ /index.php?pretty%3Bboard=$2%3Btopic=$2.$3 last;

                # And the sitemap
                rewrite ^sitemap.xml$ /index.php?action=sitemap%3Bxml last;
        }

        location ~ \.php$ {
                fastcgi_pass    127.0.0.1:1234;
                include         /etc/nginx/fastcgi_params;
        }
}