Configure the nginx PHP environment
Install nginx
Sudo apt-get install nginx
After nginx is installed, you can access: http: // localhost/
Install php
Sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt
Php5-fpm: one of the ways to work with nginx, the other is: spawn-fcgi.
Configure nginx virtual host
Add/etc/nginx/sites-available/default
Server {
Listen 90;
Index. php;
Root/usr/share/nginx/mytest/
Access_log/usr/share/nginx/mytest/acc. log combined;
Location ~ . Php $ {
Fastcgi_pass unix:/var/run/php5-fpm.sock;
Fastcgi_index index. php;
Include fastcgi_params;
}
}
Where "/var/run/php5-fpm.sock" is the listen of "/etc/php5/fpm/pool. d/www. conf", remember to restart nginx
Sudo/etc/init. d/nginx restart
Test php support
Edit "/usr/share/nginx/mytest/index. php"
<? Php
Phpinfo ();
?>
If nginx fails to be started, you can view the nginx error log.
/Var/log/nginx/error. log
Completely uninstall nginx
When configuring nginx for experiment, the configuration is incorrect, resulting in no access to the virtual host. The nginx configuration file directory (/etc/nginx) has been deleted, and I have not backed up these configuration files, so I want to reinstall nginx.
The following apt-get command is used directly.
Sudo apt-get -- purge remove nginx
Sudo apt-get install nginx
But in fact, no nginx configuration file is automatically generated, and no/etc/nginx directory is generated.
So autoremove
Sudo apt-get -- purge remove nginx
Sudo apt-get autoremove
Sudo apt-get install nginx
Prompt
Awk: cannot open/etc/nginx. conf (No such file or directory)
Although the/etc/nginx directory is generated, only some configuration files are generated.
Conf. d sites-available sites-enabled
Therefore
Sudo apt-get -- purge remove nginx
Sudo apt-get autoremove
Dpkg -- get-selections | grep nginx
List software related to nginx,
Nginx-common deinstall
Then sdfsd
Sudo apt-get -- purge remove nginx-common
Sudo apt-get install nginx
Then OK!
Reverse proxy or load
This involves the upstream command. Set a set of proxy_pass in "/etc/nginx/sites-available/default".
Upstream first_proxy {
Server 10.9.31.89: 5001 weight = 4 max_fails = 2 fail_timeout = 30 s;
}
The server command is used to specify the name and parameters of the backend server. The server name can be a domain name, IP address, port number, or UNIX Socket.
Specify proxy_pass in VM host configuration
Server {
Listen 99;
Location /{
# If the backend server returns an error of 502 or 504 execution timeout, it will be forwarded to another service in the upstream server load balancer pool for failover.
# Proxy_next_upstream http_502 http_504 error timeout invalid_header
Proxy_pass http: // first_proxy;
Proxy_set_header Host www.yourdomain.com;
Proxy_set_header X-Forwarded-For $ remote_addr;
}
}
Then you can access the 10.9.31.89: 5001 service through http: // localhost: 99. Only one backend server is configured here. If multiple backend servers are configured, simple round robin is used to achieve load performance.