commit 5bd7490 code中文原文

LNMP Tutorial & Nginx Rewrite Rules

Author
Yujia Lin
Date
Reading time
2 min read

Translated from Chinese by Claude. Read the original

[Updated July 10, 2011]

Since LNMP has been upgraded, you no longer need to set up rewrite rules for WordPress. It’s actually really simple, the kind of thing you can figure out without much Linux knowledge

I won’t say much about installing LNMP~ there’s tons online… Today I helped a buddy move his site (a WordPress site). It took me all day. With only 270MB of RAM, plus his site getting thousands and thousands of IPs, the server crashed the moment the site went up~ memory maxed out… and the site was toast! In the end I had no other option, so I tried LNMP~ This was my first time using LNMP. In the VPSYOU control panel I installed the CentOS + LNMP system image, and two minutes later the system was up. First, the database. This seems simple: go to http://你的网站地址/phpmyadmin/ (your site’s address followed by /phpmyadmin/), click Privileges, and create a new user with the same username and password as the original database user. Then create an identical database, import, and everything’s OK! As for moving the files, PuTTY makes it easy! Follow my commands:

1
2
3
4
5
6
7
8
9
10
11
cd /home/wwwroot

进入根目录

wget http://原来地址/XXXX.zip

下载打包的文件到VPS中

unzip XXXX.zip

解压zip文件

Everything’s OK! Finally, I found the rewrite rules for nginx:

1
2
3
4
5
6
7
8
9
10
11
12
location / {    
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}

Log in to the VPS with PuTTY and enter

1
vi /usr/local/nginx/conf/nginx.conf

Then type i and you can insert text. Then press ESC and enter

1
:w

Press Enter to save, then enter

1
:q

Press Enter and you’ll leave the editor. Finally, be sure to remember to restart nginx!

Enter the command

1
/usr/local/nginx/sbin/nginx -s reload

PS: I finished downloading the HD version of 5 Centimeters per Second, and it left me feeling a little down~ Sigh~ If only my life could be like that… how perfect life would be~

Esc

Keyboard shortcuts

Ctrl K /
Search and commands
j k
Next or previous post in a list
Enter
Open the selected post
h l
Older or newer post (on a post)
g h
Go to the log
g a
Go to the archive
g t
Go to tags
g s
Go to stats
t
Switch light or dark theme
r
Random post
?
Show this help