Nginx do reverse proxy +apache

Source: Internet
Author: User
Tags mysql create svn update

First the last plan, I casually draw, we also casually look at

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/4D/91/wKioL1RTUAeQsDmnAAFAnW_wHjY774.jpg "title=" 1.png " alt= "Wkiol1rtuaeqsdmnaafanw_whjy774.jpg"/>


192.168.1.119 for Nginx to do reverse proxy and processing static pages, Apache processing dynamic pages, NFS shared site home directory, SVN code management.

192.168.101 handles dynamic pages for Apache and mounts 192.168.1.119 shared directories.

192.168.1.96 is a MySQL database that allows two Web services to connect to permissions.


System use centos6.5

One, configure 192.168.1.119

1. First install the NGINX+APACHE+PHP+NFS+SVN on the 192.168.1.119

Yum install-y nginx httpd php php-mysql nfs-utils portmap Subversion

2. Modify Nginx configuration file

vim /etc/nginx/nginx.confuser  www www;worker_processes auto;error_log  / home/wwwlogs/nginx_error.log  crit;pid        /usr/local/ Nginx/logs/nginx.pid, #Specifies  the value for maximum file descriptors that  can be opened by this process.worker_rlimit_nofile 51200;events      {          use epoll;           worker_connections 51200;           multi_accept on;     }http      {          include        mime.types;          default_type   Application/octet-stream;          server_names_hash_bucket_size 128;           client_header_buffer_size 32k;           large_client_header_buffers 4 32k;           client_max_body_size 50m;           sendfile on;          tcp_nopush      on;          keepalive_timeout  60;          tcp_nodelay on;           fastcgi_connect_timeout 300;           fastcgi_send_timeout 300;           fastcgi_read_timeout 300;          fastcgi_buffer_size 64k;           fastcgi_buffers 4 64k;           fastcgi_busy_buffers_size 128k;           fastcgi_temp_file_write_size 256k;           gzip on;          gzip_min_length  1k;           gzip_buffers     4  16k;          gzip_http_version 1.0;           gzip_comp_level 2;           gzip_types       text/plain application/x-javascript  text/css application/xml;          gzip_vary on;           gzip_proxied        expired  no-cache no-store private auth;           gzip_disable         "msie [1-6]\.";            #limit_conn_zone   $binary _remote_addr  zone=perip:10m;          # #If  enable limit_conn_ zone,add  "limit_conn perip 10;"  to server section.           #log  format           log_format  access   ' $remote _ addr -  $remote _user [$time _local]  "$request"   '       &NBsp;       ' $status   $body _bytes_sent  "$http _referer"                  ' $http _user_agent '   $http _x_forwarded_ For ';upstream backend_http {     server 192.168.1.101:80;      server 127.0.0.1:88;} server     {          listen  80 default;           #listen  [::]:80 default  ipv6only=on;          server_name 192.168.1.119;           index index.html index.htm  index.php;          root  /home/wwwroot/repo;           access_log logs/access.log combined;           #location  / {           #     try_files  $uri  @ apache;          #     }            #location   @apache  {           #     internal;           #     proxy_pass http://127.0.0.1:88;           #     include proxy.conf;           #     }                    location ~  [^/]\.php (/|$)                {                     proxy_pass http:// backend_http;                     include proxy.conf;                }          location / nginx_status {                stub_status on;                access_log   off;          }           location ~ .*\. (gif|jpg|jpeg|png|bmp|swf) $               {                     expires       30d;               }           location ~ .*\. (JS|CSS)?$               {                      expires      12h;                }          access_log   /home/wwwlogs/access.log  access;     }include vhost/*. conf;} Check configuration file nginx -t start service nginx Reload configuration Nginx -s reload


3. Modifying the Apache configuration file

Vim/etc/httpd/conf/httpd.conf<virtualhost *:80> ServerAdmin [email protected] Documentroot/home/wwwroot/repo ServerName 192.168.1.119</virtualhost> start service httpd startchkconfig httpd on

4. Create an SVN repository

MKDIR/OPT/SVN && svnadmin create/opt/svn/repo using password Authentication Vim/opt/svn/repo/conf/svnerve.confpassword = Uncomment this line add user and password echo "charlie = Charlie" >>/opt/svn/repo/conf/passwd start service svnserve-d-R/OPT/SVN take out SVN warehouse cd/home/ WWWROOTSVN Co svn://localhost/repo Modify SVN update directly to the website home directory CD/OPT/SVN/REPO/HOOKSCP Post-commit.tmpl Post-commitvim Post-commitexport LANG=EN_CN. UTF-8SVN Update/home/wwwroot/repo--username Charlie--password Charlie--no-auth-cache#mailer.py Commit "$REPOS" "$REV /path/to/mailer.conf (line comment) Add Execute permissions chmod +x post-commit

5. Configure the shared directory

Vim/etc/exports/home/wwwroot/repo 192.168.1.0/24 (sync,rw,no_root_squash) Start service/etc/init.d/rpcbind START/ETC/INIT.D /nfs start viewing the shared directory Exportfs-v loading the shared directory to take effect exportfs-r

Two, configure 192.168.1.101


6. Installing httpd

Yum install-y httpd php php-mysql

7. Configure Apache

Vim/etc/httpd/conf/httpd.conf<virtualhost *:80> ServerAdmin [email protected] Documentroot/home/wwwroot/repo ServerName 192.168.1.101</virtualhost>

8. Mount the shared directory

Mkdir/home/wwwroot/repo-pvmount-t NFS 192.168.1.119:/home/wwwroot/repo/home/wwwroot/repo

9. Start the service

Service httpd Startchkconfig httpd on

Three, install MySQL

10. Install MySQL

Yum install-y MySQL Mysql-server

11. Start the service

Service mysqld Startchkconfig mysqld on

12.mysql Create password

Mysqladmin-uroot-password Charlie

13. Authorized Users

Mysql-uroot-pcharliegrant all on * * to [e-mail protected] ' 192.168.1.% ' identified by ' Charlie '; flush privileges;

Iv. Testing the website

14.SVN Export to Local

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4D/92/wKiom1RTVuDjR0CAAAE9-vJnSv4985.jpg "style=" float: none; "title=" 2.png "alt=" Wkiom1rtvudjr0caaae9-vjnsv4985.jpg "/>

Create a new test page

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/4D/92/wKioL1RTVzvwBt83AABZGGTMuX0158.jpg "style=" float: none; "title=" 3.png "alt=" Wkiol1rtvzvwbt83aabzggtmux0158.jpg "/>

Then access the test

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/4D/92/wKiom1RTVuHgwc26AACP9c9ac78718.jpg "style=" float: none; "title=" 4.png "alt=" Wkiom1rtvuhgwc26aacp9c9ac78718.jpg "/>

When the version is refreshed, the client requests that the PHP page is polled to the back-end Apache server.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4D/92/wKioL1RTVzuDaaMyAACj7w5g-EY125.jpg "style=" float: none; "title=" 5.png "alt=" Wkiol1rtvzudaamyaacj7w5g-ey125.jpg "/>

If a client requests a page that does not keep the session, it will often switch pages causing problems such as user account login, so the Nginx configuration needs to be changed

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/4D/92/wKiom1RTVuHwnx-yAABgjlmiERo615.jpg "style=" float: none; "title=" 6.png "alt=" Wkiom1rtvuhwnx-yaabgjlmiero615.jpg "/>

Add Ip_hash to keep the session connected, and then restart Nginx-s reload

Refreshing the page again does not toggle



Test the connection database, the following page is the test page

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4D/92/wKiom1RTVuKQUQccAADIwANIdgM606.jpg "style=" float: none; "title=" 7.png "alt=" Wkiom1rtvukquqccaadiwanidgm606.jpg "/>


Add and Confirm

Check to see if the file exists on both Web servers and check that the content is consistent!

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4D/92/wKioL1RTVz3yWBDnAAEINc8d2c0435.jpg "style=" float: none; "title=" 8.png "alt=" Wkiol1rtvz3ywbdnaaeinc8d2c0435.jpg "/>

Then access to prove that the backend database was successfully connected

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4D/92/wKiom1RTVuLRT89eAABOsnOUSK8040.jpg "style=" float: none; "title=" 9.png "alt=" Wkiom1rtvulrt89eaabosnousk8040.jpg "/>


This article is from the "Charlie_cen" blog, make sure to keep this source http://charlie928.blog.51cto.com/3741218/1570476

Nginx do reverse proxy +apache

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.