In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the principle and function of Nginx". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the principle and function of Nginx".
Nginx is a lightweight Web server, reverse proxy server and email proxy server.
Reverse proxy: it means that the proxy server accepts the connection request on the internet, then forwards the request to the server on the internal network, and returns the result obtained from the server to the client requesting the connection on the internet. At this time, the proxy server behaves as a reverse proxy server.
Common nginx commands:
1. Nginx-s stop: quickly close nginx, may not save relevant information, and quickly terminate the web service
2. Nginx-s quit: smoothly close nginx, save relevant information, and end web service in a scheduled way.
3. Nginx-s reload: reopen the log file
4. Nginx-c filename: specify a configuration file for nginx instead of the default
5. Nginx-t: do not run, but just test the configuration file. Nginx will check the syntax of the configuration file and try to open the file referenced in the configuration file.
6. Nginx-v: displays the version of nginx.
The main functions of nginx: http reverse proxy configuration, load balancing configuration, website configuration with multiple webapp, static site configuration, cross-domain solution.
Http reverse proxy implementation:
# run user # user nobody;# to start the process, which is usually set to equal the number of cpu # global error log # error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#PID file, recording the ID#pid logs/nginx.pid;# working mode of the currently launched nginx process and the connection limit events {worker_connections 1024 # maximum number of concurrent connections for a single background work process process} # set http server, use its reverse proxy function to provide load balancing support http {# set mime type (mail support type), the type has mime.type file definition include mime.types; default_type application/octet-stream # set log # 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 The # sendfile instruction specifies whether nginx calls the sendfile function to output the file. For ordinary applications, it must be set to on#. If it is used for downloading and other application disk IO overloaded applications, it can be set to off to balance the processing speed of disk and network uptime sendfile on;# tcp_nopush on;# O and reduce the system uptime sendfile on;# tcp_nopush on;# connection timeout # keepalive_timeout 0; keepalive_timeout 65th # compression switch # gzip on # set the actual server list Upstream zp_server1 {server 127.0.0.1 server 8089} # HTTP server server {# listen on port 80, the well-known port number is used for HTTP protocol listen 80th # define the directory # root# encoding format charset utf-8 that points to webapp using www.XX.com access server_name www.xuecheng.com;# Ssi on; ssi_silent_errors on; location / {alias Flex Universe Universe teachAccorde xcEduUI01 XcEduUI01 xcMurray UI01According to xcMUI01xcEduUI01xcEduUI01xcEduUI01xcEduUI01xcEduUI01xcEduUI01xcEduUI01 xcEduUI01 xc # listen somename:8080; # server_name somename alias another.alias; # location / {# root html; # index index.html index.htm; #} #} # HTTPS server # # server {# listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers Higger / null ssl_session_timeout MD5; # ssl_prefer_server_ciphers on; # location / {# root html; # index index.html index.htm; #} #}
Load balancing configuration: in the actual operation of a website, most of the servers are running the same app at the same time, so you need to use load balancing and shunting.
# run user # user nobody;# to start the process, which is usually set to equal the number of cpu # global error log # error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#PID file, recording the ID#pid logs/nginx.pid;# working mode of the currently launched nginx process and the connection limit events {worker_connections 1024 # maximum number of concurrent connections for a single background work process process} # set http server, use its reverse proxy function to provide load balancing support http {# set mime type (mail support type), the type has mime.type file definition include mime.types; default_type application/octet-stream # set log # 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 The # sendfile instruction specifies whether nginx calls the sendfile function to output the file. For ordinary applications, it must be set to on#. If it is used for downloading and other application disk IO overloaded applications, it can be set to off to balance the processing speed of disk and network uptime sendfile on;# tcp_nopush on;# O and reduce the system uptime sendfile on;# tcp_nopush on;# connection timeout # keepalive_timeout 0; keepalive_timeout 65th # compression switch # gzip on # set the actual server list upstream zp_server1 {# weight parameter to indicate the weight. The higher the weight, the greater the probability of being assigned. Server 127.0.0.1 weight=5; server 127.0.1 weight=1; server 127.0.1 weight=1; server 8087 weight=6;} # HTTP server server {# listens on port 80, the well-known port number for port 80 is used for HTTP protocol listen 80 # define a directory that uses www.XX.com to access server_name www.xuecheng.com;# pointing to webapp # root# encoding format charset utf-8 # Open SSI ssi on; ssi_silent_errors on; location / {proxy_pass http://zp_server1# homepage index index.html;} # another virtual host using mix of IP-, name-, and port-based configuration # # server {# listen 8000; # listen somename:8080 # server_name somename alias another.alias; # location / {# root html; # index index.html index.htm; #} #} # HTTPS server # # server {# listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers Higgl location / {# root html; # index index.html index.htm; #}}
The website has multiple webapp configurations: when a website has more and more features, it is often necessary to peel off some relatively independent modules and maintain them independently. In this case, there will usually be multiple webapp.
Http {upstream product_server {server www.helloworld.com:8081;} upstream admin_server {server www.helloworld.com:8082;} upstream finance_server {server www.helloworld.com:8083 }} server {location / {proxy_pass http://product_server} location / product/ {proxy_pass http://product_server} location / admin/ {proxy_pass http://admin_server} location / finance/ { Proxy_pass http://finance_server}}
Https reverse proxy configuration: some sites with high security requirements may use HTTPS. You need to know a few things about using nginx to configure https:
1. The fixed port number of HTTPS is 443, which is different from port 80 of HTTP.
2. The SSL standard requires the introduction of a security certificate, so in nginx.conf you need to specify the certificate and its corresponding key
Static site configuration:
Server {location / {root / app/dist/; index index.html}
Cross-domain solutions:
1 、 CORS
Set the HTTP response header on the back-end server to add the domain name you need to run and access.
2 、 jsonp
According to the first way of thinking, nginx also provides a solution that ends in cross-domain.
First: set cors in the enable-cors.conf file
Next: include-enable-cors.conf in your server to introduce cross-domain configuration.
Thank you for reading, the above is the content of "what is the principle and function of Nginx". After the study of this article, I believe you have a deeper understanding of the principle and function of Nginx, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.