Recently, nginx has been installed successfully on ubuntu, and only rewrite has not been tested. because there are multiple websites on the server, I am afraid to try it on the server. I checked some articles on the Internet and wrote another article for trial. The configuration of the virtual host on nginx is basically similar to that on apache. Notes
Recently, nginx has been installed successfully on ubuntu, and only rewrite has not been tested. because there are multiple websites on the server, I am afraid to try it on the server. I checked some articles on the Internet and wrote another article for trial.
The configuration of the virtual host on nginx is basically similar to that on apache.
Note the following:
1. about. htaccess configuration, that is, static configuration. in nginx, you usually need to write it in the configuration text of the VM, but I also see that the inclusion file is used to solve this problem, include. htaccess file, but I have not tried it.
2. how to run php and fastcgi? I don't think that this method is a good way to spread on the internet. On the contrary, I think that as an excellent reverse proxy server, we should take advantage of its reverse proxy, therefore, consider the php execution method first.
Now, go back to the topic.
Check the nginx directory structure. You probably know what to do. it is similar to apache's virtual host configuration.
Create a new file in/etc/nginx/sites-available, for example, www.blogguy.cn.
Then
vi www.blogguy.cn
The file content is as follows:
Server
{
Listen [:]: 80;
Server_name www.blogguy.cn blogguy.cn;
Root/var/www/blogguy.cn;
Index index.html index.htm index. php;
Include/etc/nginx/common. conf;
Location/nginx_status
{
Stub_status on;
Access_log off;
Allow all;
}
}
A simple explanation:
Listen is the listening port.
Server_name should be a few more words, because you may think of server_alias. In fact, server_name is the first one in nginx, followed by server_alias, therefore, in nginx, the server alias name alias does not need to be declared separately. This apache is very different.
Index is the order of searching web pages.
Include is a file. what is the use of the file contained in www.blogguy.cn? It specifies the php running mode and file cache. I may post the configuration I prompted:
Location ~ *. (Ico | css | js | gif | jpe? G | png )(? [0-9] + )? $ {
Expires max;
Break;
}
Location ~ . *. Php $ {
# Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_pass unix:/dev/shm/php-cgi.sock;
Fastcgi_index index. php;
Include/etc/nginx/fastcgi_params;
}
If ($ fastcgi_script_name ~ .. */. * Php ){
Return 403;
}
Finally, location/nginx_status is equivalent to apache's server-status.
Location/nginx_status
{
Stub_status on;
Access_log off;
Allow all;
}
Step 2: establish a soft connection to sites-enable.
ln -s /etc/nginx/sites-available/www.blogguy.cn /etc/nginx/sites-enabled/www.blogguy.cn
Do you need to check whether the configuration syntax is correct?
Check:/etc/init.d/nginx configtest
Testing nginx configuration: nginx.
If no error is returned, restart nginx.
/etc/init.d/nginx restart