Nginx in Ubuntu performs frontend calling of Apache for PHP dynamic request processing

Source: Internet
Author: User
1. create the site directory mkdir-p/srv/www/logs .... 1. create a site directory
Mkdir-p/srv/www/wangjiang.net/{logs,public_html}
2. install Nginx and enable it to listen on port 80;
Sudo apt-get install nginx
3. create a site configuration file under Nginx and try to let Nginx load any requested files or directories.
Apache processes requests for PHP files.
Nginx occupies port 80, filters static requests, and then dynamically requests the Proxy to port 8080 of Apache. The advantage of Proxy reverse Proxy is that port 80 is always used during access, and visitors will not notice any difference.
Sudo vi/etc/nginx/sites-available/wangjiang.net
Server {
Listen 80;
Access_log/srv/www/wangjiang.net/logs/nginx.access.log;
Error_log/srv/www/wangjiang.net/logs/nginx.error.log;
Root/srv/www/wangjiang.net/public_html;
Index. php index.html;
Server_name wangjiang.net;
Location \{
Try_files $ uri/index. php/$ uri;
}
Location ~ * ^. * \. Php $ {
If (! -F $ request_filename ){
Return 404;
}
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Proxy_set_header Host $ host;
Proxy_pass http: // 127.0.0.1: 8080;
}
Location ~ /\. (Ht | git ){
Deny all;
}
}
Sudo ln-s/etc/nginx/sites-available/wangjiang.net/etc/nginx/sites-enabled/wangjiang.net
 
Sudo nginx-t
Sudo/etc/init. d/nginx restart
Www.2cto.com
 
4. Apache listeners process dynamic requests;
Sudo apt-get install apache2
Sudo vi/etc/apache2/sites-available/wangjiang.net

ServerName mysite.com
DocumentRoot/var/www/wangjiang.net/public_html/
CustomLog/var/www/wangjiang.net/logs/apache.access.log common
ErrorLog/var/www/wangjiang.net/logs/apache.error.log

Sudo a2ensite wangjiang.net
Sudo/etc/init. d/apache2 reload
Sudo/etc/init. d/apache2 restart
Copy code
5. install the PHP module and mysql
Sudo apt-get install mysql-server php5 php5-mysql php5-suhosin
Sudo/etc/init. d/apache2 restart
Copy code
6.
Ubuntu hosts modification
1. modify hosts
Sudo gedit/etc/hosts
2. add resolution record (.)
127.0.0.1 wangjiang.net
3. save and restart the network.
Sudo/etc/init. d/networking restart
7. modify Apache listening port 8080
Sudo vi/etc/apach2/ports. conf
Namevirtualhost*: 8080
Listen 8080.

From zendwang

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.