: This article describes how to configure the virtual host vhost in nginx. if you are interested in the PHP Tutorial, refer to it. First, let's talk about your own understanding.
The so-called virtual host means that the nginx environment can be reached through several different URLs, but the processing logic is different for different URLs. Nginx supports virtual hosts, but the browsers and other clients do not know. Therefore, several addresses of the virtual hosts should all point to the IP address of nginx, so that the functions of the virtual host can be normal.
The following describes the configuration of virtual hosts in the nginx environment.
Assume that the virtual host domain we want to configure is mail.zjc.com.
The VM storage directory is/var/www/mail.zjc.com/web.
sudo mkdir -p /var/www/mail.zjc.com/web
Create an nginx VM configuration file
sudo gedit /etc/nginx/sites-available/mail.zjc.com.vhost
The content is (where the php domain is configured based on the local php application)
server { listen80; server_name mail.zjc.com; root /var/www/mail.zjc.com/web; if ($http_host != "mail.zjc.com") { rewrite ^http://mail.zjc.com$request_uripermanent; } index index.php index.html; location = /favicon.ico { log_not_foundoff; access_logoff; } location = /robots.txt { allow all; log_not_foundoff; access_logoff; } # Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!location~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ { deny all; } # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).location~ /\. { deny all; access_logoff; log_not_foundoff; } location~* \.(jpg|jpeg|png|gif|css|js|ico)$ { expires max; log_not_foundoff; } location~ \.php$ { try_files$uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_passunix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }}
Because the nginx main configuration file nginx. conf will automatically apply the configuration file in sites-enabled, we need to create a link to the mail.zjc.com. vhost file in sites-enabled.
cd /etc/nginx/sites-enabledsudo ln -s /etc/nginx/sites-available/mail.zjc.com.vhost www.zjc.com.vhost
Reload nginx to make the configuration take effect
sudo /etc/init.d/nginx reload
Now, in/var/www/mail.zjc.com/web
Directory to create some files (such as index. php) throughhttp://mail.zjc.com/index.php
. BTW, remember to set mail.zjc.com to the IP address of nginx in hosts or DNS.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above describes how to configure the virtual host vhost in nginx, including some content, and hope to help anyone interested in the PHP Tutorial.