Create the Vhosts directory under the Conf directory and create the site's configuration file, taking examples.com.conf as an example.
The code is as follows |
Copy Code |
[Root@localhost ~]# cd/usr/local/nginx/ [Root@localhost nginx]# mkdir-p conf/vhosts [Root@localhost nginx]# Vim conf/vhosts/examples.com.conf |
The examples.com.conf configuration file created is as follows:
The code is as follows |
Copy Code |
# virtual hosts are defined with the server server { # Listening ports, spacing between multiple ports using spaces Listen 80; # used to define access to the IP address or domain name, multiple domain names separated by a space server_name examples.com www.examples.com; # used to specify the default encoding format for site pages CharSet Utf-8;
# used to specify the access log storage path for this site, followed by main to set the format of the log #access_log Logs/examples.com.access.log Main;
# used to specify the page root of the site, either relative (relative to Nginx installation directory), or absolute path #root/www/examples.com # Use to specify the default home address for access #index index.html index.php
# Use to specify settings for site default access, where root and index usage and effects are the same as above # It's OK to use either of these two ways, using the location/{} approach Location/{ root/www/examples.com; Index index.html index.php; }
# Use the error_page instruction to set the return page for various error messages # The return page size of the error message if less than 512k will be replaced by IE browser with IE default error page #error_page 404/404.html; Error_page 502 503 504/50x.html; Location =/50x.html { root HTML; }
# Nginx's location directive is used to set URL address matching, to support regular expression matching, and to support conditional judgment matching. # The Nginx can be used to filter the dynamic and static Web pages through the location instruction. # The following is a 30 day cache for all picture settings Location ~. *. (gif|jpg|jpeg|png|bmp|swf) $ { Expires 30d; } # Cache for JS and CSS files for 1 hours Location ~. *. (JS|CSS) $ { Expires 1h; }
# The following is a list of two ways to parse PHP: # The first is simply to give all PHP end requests to the local 8080 port for processing #location ~ php$ { # Proxy_pass http://127.0.0.1:8080; #} # The second is to give the PHP request to the FASTCGI process listening to the IP address and port, which is forwarded to PHP_FPM Location ~. php$ { # set to parse the root directory of PHP, typically the site root root/www/examples.com; # address and Port are consistent with PHP_FPM settings Fastcgi_pass 127.0.0.1:9000; # Default Home Fastcgi_index index.php; # Specifies to prevent the PHP dynamic program from the home directory, that is, the path specified before $fastcgi_script_name, it is recommended to be consistent with the site root directory or directly using $document_root Fastcgi_param script_filename $document _root$fastcgi_script_name; Include Fastcgi_params; }
# Prevent direct access to. htaccess files, recommended to open Location ~/.ht { Deny all; } } |
Finally, create the root directory of the Web site and set directory permissions:
The code is as follows |
Copy Code |
[Root@localhost ~]# mkdir-p/www/examples.com # Write permission [Root@localhost ~]# chmod +w/www/examples.com [Root@localhost ~]# chown-r www:www/www/examples.com # Create a test PHP file [Root@localhost ~]# echo " Phpinfo ();?> ">>/www/examples.com/phpinfo.php |
After starting PHP-FPM and Nginx this time, you should be able to access http://www.examples.com/phpinfo.php directly.