Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure the static and dynamic separation of Nginx with Apache or Tomcat

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article Xiaobian for you to introduce in detail "Nginx with Apache or Tomcat separation of how to configure", detailed content, clear steps, details handled properly, I hope that this "Nginx with Apache or Tomcat separation of how to configure" article can help you solve doubts, the following with the editor's ideas slowly in-depth, together to learn new knowledge.

1. Static and dynamic separation configuration of nginx and apache:

Put the following configuration in the corresponding server {} in the nginx configuration file. If you use a different port number, just change it:

# all dynamic pages of php are handled by apache

Location. (php)? ${proxy_set_header host $host;proxy_set_header x-real-ip $remote_addr;proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;proxy_pass http://127.0.0.1:88;}

# all static files are read directly by nginx without going through apache

Location ~. *\. (htm | html | gif | jpg | jpeg | png | bmp | swf | ioc | rar | zip | txt | flv | mid | doc | ppt | pdf | xls | mp3 | wma) ${expires 15d;} location ~. *\. (js | css)? ${expires 1h;}

If you previously set fastcgi, comment out the following configuration:

# pass the php scripts to fastcgi server listening on 127.0.0.1:9000##location ~\. Php$ {# root / var/www/html;# fastcgi_pass 127.0.0.1

Restarting nginx takes effect, as shown in the figure. The header shows that apache is displayed in the nginx,phpinfo, indicating that the separation of movement and movement takes effect.

Static and dynamic separation configuration of 2.niginx and tomcat:

# Master profile configuration

[root@localhost ~] # vi / usr/local/nginx/conf/nginx.confuser nginx;worker_processes 1: errorists log logs/error.log;pid logs/nginx.pid;events {worker_connections 1024;} http {include mime.types; default_type application/octet-stream # Log format definition log_format main'$remote_addr-$remote_user [$time_local] "$request"'$status $body_bytes_sent "$http_referer"'"$http_user_agent"$http_x_forwarded_for"; access_log logs/access.log main; sendfile on; keepalive_timeout 65; # gzip compression function sets 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-javascripttext/css application/xml; gzip_vary on; server {listen 80; server_name www.test.com; location / {# jsp website program root directory, usually nginx and tomcat are in the same directory root / usr/local/tomcat/webapps/root; index index.html index.jsp index.html } location ~. * .jsp$ {index index.jsp; proxy_pass http://127.0.0.1:8080; # from the jsp request to tomcat for processing proxy_redirect off; proxy_set_header host $host; # the web server at the back end can obtain the user's real ip proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for through x-forwarded-for Client_max_body_size 10m; # maximum single file bytes allowed for client requests client_body_buffer_size 128k; # buffer proxy buffer maximum client requests proxy_connect_timeout 90; # nginx and backend server connection timeout (proxy connection timeout) proxy_read_timeout 90 # after a successful connection, the response time of the back-end server (proxy receiving timeout) proxy_buffer_size 4k; # set the buffer size of the proxy server (nginx) to store account information proxy_buffers 632k; # proxy_buffers buffer, if the average web page is less than 32k, set proxy_busy_buffers_size 64k # proxy_buffers*2 proxy_temp_file_write_size 64k under heavy load; # set cache folder size, greater than this value, will be transferred from upstream server} location ~. *\. (gif | jpg | png | bmp | swf) $# static pages {expires 30d are processed by nginx; # using expires cache module, cached to the client for 30 days} location ~. *\. (jsp | js | css)? ${expires 1d } error_page 404 / 404.html; # error page error_page 500502 503504 / 50x.html; location = / 50x.html {root html;}}

# write nginx start, stop, restart and other sysv management scripts for ease of use

[root@localhost ~] # vi / ETC instart init.dGinxActionBash # chkconfig: 345 99 2 pound description: nginx servicecontrol scriptprog= "/ usr/local/nginx/sbin/nginx" pidf= "/ usr/local/nginx/logs/nginx.pid" case "$1" instart) $progecho "nginx servicestart success."; stop) kill-s quit $(cat $pidf) echo "nginx service stopsuccess."; restart) $0 stop$0 start;;reload) kill-s hup $(cat $pidf) echo "reload nginx configsuccess." *) echo "usage: $0 {start | stop | restart | reload}" exit 1esac [root@localhost ~] # chmod + x / etc/init.d/nginx [root@localhost ~] # service nginx restart [root@localhost ~] # chkconfig-- add nginx [root@localhost ~] # chkconfig nginx on has finished introducing the article "how to configure Nginx with Apache or Tomcat separation". If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report