1 Installing Nginx
Installing the sudo apt-get install Nginx
Start Service Nginx Start
The browser tests whether the installation was successful http://192.168.2.173/
2 Installing PHP5
sudo apt-get install PHP5-FPM
3 Installing the MySQL 5 database
sudo apt-get install mysql-server mysql-client
4 Let PHP5 support MySQL
sudo apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5 -ming php5-ps Php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl PHP-APC
5 Configuring Nginx
The original configuration file/etc/nginx/nginx.conf configuration is not very easy to understand, you can refer to: Http://wiki.nginx.org/NginxFullExample and http://wiki.nginx.org/ NginxFullExample2
Here the main write down configure the default virtual host
File location /etc/nginx/sites-available/default
Back up Cp/etc/nginx/sites-available/default/etc/nginx/sites-available/default_bak before modifying
Below is a description of my personal configuration
# you could add here your# server {# ... #}# statements for each of the your virtual hosts to this file### your should look At the following URL ' s-grasp a solid understanding# of Nginx configuration files in order to fully unleash th E power of nginx.# http://wiki.nginx.org/Pitfalls# http://wiki.nginx.org/QuickStart# http://wiki.nginx.org/ configuration## generally, you'll want to move this file somewhere, and start with a clean# file but keep this around fo R reference. Or just disable in sites-enabled.##-see/usr/share/doc/nginx-doc/examples/for more detailed examples.# #server { Listen default_server; Listen [::]:80 default_server Ipv6only=on; root/home/ming/www; Index index.php index.html index.htm; #添加了index. PHP # Make site accessible from http://localhost/server_name localhost; Location/{# First attempt-serve request as file, then # as directory, then fall back T o DisplayiNg a 404. Try_files $uri $uri/= 404; # Uncomment to enable Naxsi in this location # Include/etc/nginx/naxsi.rules} # only for NG Inx-naxsi used with nginx-naxsi-ui:process denied requests #location/requestdenied {# proxy_pass H ttp://127.0.0.1:8080; #} #error_page 404/404.html; # REDIRECT Server error pages to the static page/50x.html # #error_page 502 503 504/50x.html; Location =/50x.html {root/home/ming/www; #我的网站目录}# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { Try_files $uri = 404; #增加这行, used to avoid 0day vulnerabilities Fastcgi_split_path_info ^ (. +\.php) (/.+) $; # # Note:you should has "cgi.fix_pathinfo = 0;" In PHP.ini # # # with php5-cgi alone: # Fastcgi_pass 127.0.0.1:9000; # with PHP5-FPM: Fastcgi_pass Unix:/var/run/php5-fpm.sock; Fastcgi_index index.php; Include Fastcgi_params; } # Deny access to. htaccess files, if Apache ' s document Root # concurs with Nginx ' s one # #lo cation ~/\.ht {# deny all; #}}# Another virtual host using mix of ip-, name-, and port-based configuration# #server {# listen 8000;# liste n somename:8080;# server_name somename alias another.alias;# root html;# index index.html index.htm;## Location/{# try_files $uri $uri/=404;#}#}
How to configure a virtual host for a multi-domain
For example, create a virtual domain name linux.test.kunming.com
1 creating files in the/etc/nginx/sites-available directory linux.test.kunming.com
Vim linux.test.kunming.com
Add the following content
server {Listen default_server; Listen [::]:80 default_server Ipv6only=on; root/home/ming/www/linux.test.kunming.com; #这里就是域名指向的网站目录 index index.php index.html index.htm; # make site accessible from Http://localhost/server_name linux.test.kunming.com; #虚拟域名 location/{# First attempt-serve request as file, then # as directory, the N Fall back to displaying a 404. Try_files $uri $uri/= 404; # Uncomment to enable Naxsi in this location # Include/etc/nginx/naxsi.rules} # only for NG Inx-naxsi used with nginx-naxsi-ui:process denied requests #location/requestdenied {# proxy_pass H ttp://127.0.0.1:8080; #} #error_page 404/404.html; # REDIRECT Server error pages to the static page/50x.html # #error_page 502 503 504/50x.html; Location =/50x.html {Root/home/ming/www; # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { Try_files $uri = 404; #增加这行, used to avoid 0day vulnerabilities Fastcgi_split_path_info ^ (. +\.php) (/.+) $; # # Note:you should has "cgi.fix_pathinfo = 0;" In PHP.ini # # # with php5-cgi alone: # Fastcgi_pass 127.0.0.1:9000; # # with Php5-fpm:fastcgi_pass Unix:/var/run/php5-fpm.sock; Fastcgi_index index.php; Include Fastcgi_params; } # Deny access to. htaccess files, if Apache ' s document Root # concurs with Nginx ' s one # #lo cation ~/\.ht {# deny all; #}}
2 Setting up a soft connection and restarting the server
sudo ln-s/etc/nginx/sites-available/linux.test.kunming.com/etc/nginx/sites-enabled/ Linux.test.kunming.com
sudo service Ngnix restart
3 Test Create a folder under the/home/ming/www directory under the site Directory linux.test.kunming.com
Cd/home/ming/www
mkdir linux.test.kunming.com
CD linux.test.kunming.com
Vim index.php
Type test Content
<? PHP echo 1111;
4 because Linux is installed in the local virtual machine to be parsed in the host in the local environment
Modify the C:\Windows\System32\drivers\etc\hosts file to add the following:
192.168.2.173 linux.test.kunming.com
5 The browser input linux.test.kunming.com appears as follows
Indicates successful test
Linux LNMP Environment installation notes