Add Nginx Virtual Host
This assumes that everyone's Nginx server has been installed, do not understand the official documentation of the Linux distributions or LNMP installation instructions. Configure Virtual host steps as follows:
Enter the/usr/local/nginx/conf/vhost directory to create the virtual host configuration file demo.neoease.com.conf ({domain name}.conf).
Open the configuration file and add the following services:
The code is as follows |
Copy Code |
server { Listen 80; server_name www.topjishu.net; Index index.html index.htm index.php; Root/var/www/www.topjishu.net; Log_format www.topjishu.net ' $remote _addr-$remote _user [$time _local] $request ' $status $body _bytes_sent $http _refe RER ' $http _user_agent $http _x_forwarded_for '; Access_log/var/log/www.topjishu.net.log www.topjishu.net; } |
Open the Nginx profile/usr/local/nginx/conf/nginx.conf and introduce the virtual host configuration file into the HTTP scope as follows:
Include vhost/*.conf;
Restart the Nginx service and execute the following statement.
Service Nginx Restart
let the Nginx virtual host support PHP
In the previous 2nd step of the virtual Host service corresponding directory to add support for PHP, here is the use of FastCGI, modified as follows.
code is as follows |
copy code |
server { Listen 80; server_name www.topjishu.net; Index index.html index.htm index.php; Root/var/www/www.topjishu.net; Location ~. *. (PHP|PHP5)? $ { Fastcgi_pass unix:/tmp/php-cgi.sock; Fastcgi_index index.php; I Nclude fcgi.conf; } Log_format www.topjishu.net ' $remote _addr-$remote _user [$time _local] $request ' $status $body _bytes_sent $http _ Referer ' $http _user_agent $http _x_forwarded_for '; Access_log/var/log/www.topjishu.net.log www.topjishu.net; } |
picture anti-theft chain
Picture as an important static resource of large traffic, perhaps the site owner does not want other sites to be directly referenced, Nginx can referer to prevent outbound hotlinking pictures.
code is as follows |
copy code |
server { Listen server_name www.topjishu.net; Index index.html Index.htm index.php; Root/var/www/www.topjishu.net; # Add a 1-year expiration date for the picture, and prohibit Google, Baidu, and sites outside the site from referencing images Location ~. Ico|jpg|jpeg|png|gif) $ { expires 1y; Valid_referers none blocked demo.neoease.com *.google.com; if ($invalid _referer) { return 404 } } Log_format www.topjishu.net ' $remote _addr-$remote _user [$time _local] $request ' $status $body _bytes_sent $ht Tp_referer ' $http _user_agent $http _x_forwarded_for '; Access_log/var/log/www.topjishu.net.log www.topjishu.net; } |
WordPress pseudo static configuration
If the WordPress link structure is set to/%postname%/,/%postname%.html and other formats, you need rewrite URL, WordPress provides Apache. htaccess modify the proposal, but did not inform Ngi NX how to modify it. We can modify the virtual host configuration of WordPress as follows:
The code is as follows |
Copy Code |
server { Listen 80; server_name www.topjishu.net; Index index.html index.htm index.php; Root/var/www/www.topjishu.net; Location/{ 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; } } rewrite/wp-admin$ $scheme://$host $uri/permanent Location ~ ... (PHP|PHP5)? $ { Fastcgi_pass unix:/tmp/php-cgi.sock; Fastcgi_index index.php; include fcgi.conf; } Log_format www.topjishu.net ' $remote _addr-$remote _user [$time _local] $request ' $status $body _bytes_sent $http _ Referer ' $http _user_agent $http _x_forwarded_for '; Access_log /var/log/www.topjishu.net.log demo.neoease.com; } |
The
Lnmp Suite, which provides WordPress as a static profile/usr/local/nginx/conf/wordpress.conf, is referenced in the server scope of the virtual host configuration as follows.
include wordpress.conf;
If you use the Lnmp suite, enter the WordPress backstage discovery will appear 404 pages, wp-admin behind the missing ramp/, please add the following statement at wordpress.conf last:
rewrite/wp -admin$ $scheme://$host $uri/permanent;
Relative to Apache, Nignx has a more powerful concurrency capability, and because it consumes less resources for process management. Apache has more mature and usable modules than Nginx, and fewer bugs.
Vendor IDC chooses Nignx, because high concurrency allows them to create more virtual host space for more money; Taobao also transformed Nignx (Tengine) as a CDN server, can withstand greater pressure.