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 build NGINX on CentOS7 Server

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to build CentOS7 server NGINX, I hope you will learn something after reading this article, let's discuss it together!

Yum source installation document for nginx: http://nginx.org/en/linux_packages.html

Installation mode

Create a yum source file

Vim / etc/yum.repos.d/nginx.repo

Add the following

[nginx] name=nginx repobaseurl= http://nginx.org/packages/centos/7/$basearch/gpgcheck=0enabled=1

Execute the command:

Yum install nginxsystemctl start nginxsystemctl enable nginx profile

Modify the configuration file

Vim / etc/nginx/nginx.conf increases concurrency # the total concurrency is worker_processes*worker_connections. If a reverse proxy is used, a request consumes two connections (one for the client and one for the back-end tomcat). # is generally the same as the number of cores of cpu. For example, if there is a cpu with 4 cores for each cpu, it will be set to 4 for 2 CPU and for each cpu with 4 cores, it will be set to 8. Worker_processes 1 worker_connections events {worker_connections 20480;} http {. # the original configuration does not need to be changed, and the following configuration is added. # sibling agents do not need redirect. Such as the root directory proxy to the root directory. Proxy_redirect off; # solves the problem of getting access domain names. Otherwise, the method cannot get the domain name requested: request.getServerName (); proxy_set_header Host $host; # solves the problem of obtaining the visitor's IP address. Proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # solves the WebSocket Proxy problem. Nginx document: https://www.nginx.com/blog/websocket-nginx/ proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; # maximum size of the request body, mainly for uploading files. The default is 1m client_max_body_size 4000m; # request body cache, and temporary files are written if the cache value is exceeded. Default is 16k client_body_buffer_size 128k; # enable ssi ssi on; ssi_types text/shtml; # enable gzip gzip on; # enable compression refers to the minimum file, default is 20. Files that are too small are likely to get bigger and bigger, so it is more appropriate to set it to 1000. Gzip_min_length 1000; # compression level, 1-9, the larger the compression, the smaller the compression, but also the slower and more expensive CPU. The default is 1. A setting of 2 is generally sufficient, and the pursuit of a higher compression ratio can be set to 5. No matter how high it is. When gzip_comp_level 2; # is used as a proxy, gzip is unconditionally enabled. Gzip_proxied any; # gzip_proxied expired no-cache no-store private auth; # any type of compression to avoid setting one by one, easy to miss. Gzip_types *;} integrate tomcat

Create a profile. All files ending with .conf in the / etc/nginx/conf.d/ directory are loaded automatically.

Vim / etc/nginx/conf.d/jspxcms.conf

The configuration file is as follows:

Server {listen 80; server_name www.jspxcms.com; root / data/tomcat/jspxcms/webapps/ROOT; index index.html index.htm index.shtml; location / {# if the file or directory corresponding to the uri address does not exist, forward it to tomcat # try_files $uri $uri/index.html $uri/index.htm @ proxypass using a proxy # find a directory can redirect files to a directory using nginx. If you visit / foo, the directory will be redirected to / foo/ try_files $uri $uri/ @ proxypass;} # if you use try_files $uri $uri/ @ proxypass;, you must add this item, otherwise the home page may not be accessible location = / {try_files / index.html @ proxypass } location @ proxypass {# Agent to tomcat,tomcat to listen to port 10001 proxy_pass http://localhost:10001;} # disable access to the file location / WEB-INF/ {deny all;}} # redirect jspxcms.com to www.jspxcms.comserver {listen 80; server_name jspxcms.com; rewrite ^ / (. *) http://www.jspxcms.com/$1 permanent;}

If restful is not used, only specific url suffixes are proxied, and the following configuration can be used:

Server {listen 80; server_name www.jspxcms.com jspxcms.com; if ($host = 'jspxcms.com') {rewrite ^ / (. *) $http://www.jspxcms.com/$1 permanent;} location ~\. (jsp | jspx | do | servlet)? (\; jsessionid=.*)? ${proxy_pass http://localhost:10001;} location / {root / home/jspxcms/webapps/ROOT Index index.html index.shtml index.jspx index.do;} location / WEB-INF/ {deny all;}} after reading this article, I believe you have some understanding of "how to build NGINX on CentOS7 server". If you want to know more about it, please follow the industry information channel. Thank you for reading!

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

Development

Wechat

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

12
Report