Nginx is a lightweight web server software. It has the following advantages: free, open-source, high-performance, stable, powerful, simple configuration, and resource consumption.
Nginx is a lightweight web server software. It has the following advantages: free, open-source, high-performance, stable, powerful, simple configuration, and resource consumption.
Nginx is a lightweight web server software. It has the following advantages: free, open-source, high-performance, stable, powerful, simple configuration, and low resource consumption.
My operating system is ubuntu12.04, 32-bit. Before installing nginx + php + mysql, make sure that your apache server is disabled.
Assume the IP address is 127.0.0.1.
1. First install mysql, run the following command on the terminal: sudo apt-get install mysql-server mysql-client. During installation, the system will prompt you to enter the password twice.
2. install nginx. Enter the command sudo apt-get install nginx on the terminal.
3. start ngnix and enter the command sudo/etc/init. d/nginx start on the terminal.
In this case, you can enter an IP address in the browser to verify that nginx is working properly. If it is successful, it is as follows:
4, install php5, enter the command: sudo apt-get install php5-fpm, php5-fpm is a daemon, run FastCGI server port 9000.
5. Configure nginx:
Sudo vim/etc/nginx/sites-available/default: Compare the original content with the image configuration below.
My configuration files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 10 |
# You may add here your # Server { #... #} # Statements for each of your virtual hosts to this file ## # You shoshould look at the following URL's in order to grasp a solid understanding # Of Nginx configuration files in order to fully unleash the power of Nginx. # Http://wiki.nginx.org/Pitfalls # Http://wiki.nginx.org/QuickStart # Http://wiki.nginx.org/Configuration # # Generally, you will want to move this file somewhere, and start with a clean # File but keep this around for reference. Or just disable in sites-enabled. # # Please see/usr/share/doc/nginx-doc/examples/for more detailed examples. ## Server { Listen 80; # listen for ipv4; this line is default and implied Listen [:]: 80defaultipv6only = on; # listen for ipv6 Root/usr/share/nginx/www; Indexindex.htmlindex.htm index. php; # Make site accessible from http: // localhost/ Server_namelocalhost; Location /{ # First attempt to serve request as file, then # As directory, then fall back to index.html Try_files $ uri // index.html; } Location/doc { Root/usr/share; Autoindexon; Allow127.0.0.1; Denyall; } Location/images { Root/usr/share; Autoindexoff; } # Error_page 404/404 .html; # Redirect server error pages to the static page/50x.html # # Error_page 500 502 503 504/50 x.html; Location =/50x.html { Root/usr/share/nginx/www; } # Proxy the PHP scripts to Apache listening on 127.0.0.1: 80 # # Location ~ \. Php $ { # Proxy_pass http: // 127.0.0.1; #} # Pass the PHP scripts to FastCGI server listening on Fig: 9000 # Location ~ \. Php $ { Fastcgi_pass127.0.0.1: 9000; Fastcgi_indexindex.php; Includefagi_params; } # Deny access to. htaccess files, if Apache's document root # Concurs with nginx's one # Location ~ /\. Ht { Denyall; } } # Another virtual host using mix of IP-, name-, and port-based configuration # # Server { # Listen 8000; # Listen somename: 8080; # Server_name somename alias another. alias; # Root html; # Index index.html index.htm; # # Location /{ # Try_files $ uri // index.html; #} #} # HTTPS server # # Server { # Listen 443; # Server_name localhost; # # Root html; # Index index.html index.htm; # # Ssl on; # Ssl_certificate cert. pem; # Ssl_certificate_key cert. key; # # Ssl_session_timeout 5 m; # # Ssl_protocols SSLv3 TLSv1; # Ssl_ciphers ALL :! ADH :! EXPORT56: RC4 + RSA: + HIGH: + MEDIUM: + LOW: + SSLv3: + EXP; # Ssl_prefer_server_ciphers on; # # Location /{ # Try_files $ uri // index.html; #} |
Save the file and restart nginx. You can use ": wq! "Write and force save launch. The command to restart nginx is sudo/etc/init. d/nginx restart. After that, you can test whether php is running normally. The specific method is as follows: 1> Create phpinfo and run sudo vim/usr/share/nginx/www/info. php. Then enter the following code segment:
After saving and exiting, enter http: // 127.0.0.1/info. php In the browser to test.
6. For php to obtain mysql support, a module is required:
Install the php module: sudo apt-cache search php5, and then install the software: sudo apt-get install php5-mysql php5-curl php5-gd php5-idn php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite.
Restart php-fpm now and use the command: sudo/etc/init. d/php5-fpm restart.
Then refresh in the browser: http: // 127.0.0.1/info. php to see if the installed modules are supported. The effect should be as follows:
So far, a lump environment has been set up.
After that, you can configure the server root directory for specific projects as follows:
View the default file in the sites-enabled directory and modify it as shown in:
Restart the nginx server and open localhost to view the web page of your project.