Nginx reverse proxy configuration with Apache backend federated configuration: Description: Nginx maps http to a specific subdirectory on Apache. Configuration method steps: 1. Set the domain name, the sub-domain map to the specified server ip,2. Nginx set up the server, as well as the corresponding directory, or forward to the specified Apache port. Server { Listen default_server; Listen [::]:80 default_server IPV 6only=on; root/usr/share/nginx/html; Index index.html index. htm; # make site accessible from http://localhost/ SERVER_NAME localhost; location/{ # First A Ttempt to serve request as file, then # as Directory, then fall BAC K to displaying a 404. try_files $uri $uri/=404; &NBS P # Uncomment to enable Naxsi in this location &NBSP # include/etc/nginx/naxsi.rules } # only for NG Inx-naxsi used with Nginx-naxsi-ui:process denied requests #location/requestdenied { & nbsp # Proxy_pass http://127.0.0.1:8080; #} #error_page 404/404.h tml; # REDIRECT Server error pages to the static page/50x.html &NBSP ; # #error_page 502 503 504/50x.html; #location =/50x.html {&nbs P # root/usr/share/nginx/html; #} & nbsp # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # &NBS P #location ~ \.php$ { # Fastcgi_split_path_info ^ (. +\.php) (/.+) $;&NB SP # # note:you should has "cgi.fix_pathinfo = 0;" In php.ini # # # with php5-cgi alone: # &NB Sp 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
#
#location ~/\.ht {
# Deny All;
#}
}
server{
Listen 80;
server_name nginx.xxxx.com;
Location/{
root/usr/share/nginx/html/www.xxxx.com;
Index index.html;
}
}
server{
Listen 80;
server_name www.xxxx.com apache.xxxx.com; index index.html; location/{ &N Bsp Proxy_pass http://localhost:8080/www.xxxx.com/; &NBS P Proxy_redirect default; }} # Another virtual host using mix of ip-, name-, and port-based configuration# #server {# Listen 8000;# Listen somename:8080;# &NBS P server_name somename alias another.alias;# root html;# Index index.html index.ht m;## location/{# try_files $uri $uri/=404;#   ; }#} 3. Apache is set to ports.conf, set to 2 in the same (8080), and also note the ports in the files under the Configuration Sites_enable folder. <virtualhost *:8080> # The SERVERNAME directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of the virtual hosts, the servername # Specifies-hostname must appear in the RE Quest ' s Host:header to # match this virtual Host. For the default virtual host (this file) this # value are not decisive as it's used as a last R Esort host regardless. # However, you must set it for any further virtual host explicitly.  ; ServerName www.xxxx.com ServerAdmin [email protected] & nbsp documentroot/var/www/html # Available Loglevels:trace8, ..., Trace1, Debu G, info, notice, warn, # error, Crit, alert, emerg. # It's also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn errorlog ${apache_log_dir}/error .log Customlog ${apache_log_dir}/access.log combined 4. Start Nginx Load new configuration, restart apache 4.1 start Nginx, only Nginx, if you modify the configuration after restarting, you need nginx-s reload. Close: nginx-s stop 4.2 apache2ctl restart 5. View port usage: NETSTAT-ANOP | grep 80 6. The expiration policy of Apache Mod_expires and Mod_cacheapache can be set via Apache Mod_expires and mod_headers two modules:
1) Module Mod_expires settings:Allow configuration file to control http "Expires" and "Cache-control" header content Mod_expires module's main role is to automatically generate the page header information Expires tags and cache-control tags, Thus reducing the frequency and number of clients access, to reduce unnecessary traffic and increase access speed of the purpose Mod_expires is the more simple configuration of the Apache many modules, it has only three instructions expiresactive directive: Open or close to produce "Expires:" and "Cache-control:" The function of the head. EXPIRESBYTYPE directive: Specifies the expiration time of the MIME-type document (for example: text/html). ExpiresDefault directive: The default time for all documents to expire. Expiration Time "Access plus 1 month" "Access plus 4 weeks" "Now plus" "modification plus 5 hours 3 minutes" A2592000M604800ACC The ESS, now, and a three are written in the same way, meaning that the expiration time is calculated from the point of access. The meaning of modification and M is the same, which means that the expiration time is calculated based on the last modification time of the file being accessed. Therefore, the latter method only works on static files, and the dynamic pages generated by the script are not affected by it.
Configuration instance:Expiresactive on (Turn on mod_expires function) ExpiresDefault "Access plus 6 months" (the default expiration time is 6 months) Expiresbytype image/* "Access p LUs years "(Picture file type cache time is 10) expiresbytype text/*" Access plus years "(text type cache time is 10) Expiresbytype application/* "Access plus minutes" (application file type cache 30 minutes) Verify that Image/jpeg cache time is 315360000s (10) if the image/ JPEG set to not cache (set max-age to 0s): # expiresbytype image/* "Access plus years" Expiresbytype image/* A0
2) Module mod_headers settings:# Year (Flv,gif,ico file type cache time is 1 years) header set Cache-control "max-age=2592000″# WEEK (pdf.swf,js,css cache time is one week) header set Cach E-control "max-age=604800″# never cache (Jsp.swf,ico file type not cached) header set Expires" Thu, DEC 2003 16:00:00 GMT "header set Cache-control "No-store, No-cache, must-revalidate" Header set Pragma "No-cache"
Nginx reverse Proxy and Apache backend configuration federated configuration