Nginx main configuration parameters, Nginx configuration website, and nginx Parameters

Source: Internet
Author: User
Tags sendfile nginx server

Nginx main configuration parameters, Nginx configuration website, and nginx Parameters
1. Detailed description of parameters in the main configuration file

A. Install nginx in Linux. Blog address: http://www.cnblogs.com/cindy-cindy/p/6847499.html

B. after Nginx is installed, a corresponding installation directory is displayed, which contains nginx. confg is the main configuration file of nginx. The main configuration file of nginx is divided into four parts: main (global configuration), server (host configuration), and upstream (server Load balancer settings) and location (the URL matches the settings of a specific location). The relationship between these four is: server inherits main, location inherits server, and upstream neither inherits other settings nor is inherited.

C. nginx is a proxy server. Generally, websites cannot be deployed under Nginx. For example, Java Web programs developed using Java are deployed under tomcat, then, point the website address to tomcat using the Nginx proxy.

2. Nginx. conf configuration file description (Remarks)
1 # kencery annotation Nginx file 2 # Time: 3 # learning content, only from the Internet, please contact me to delete any copyright issues. 4 5 ######## Nginx main (global configuration) file 6 # specify the users and user groups for running nginx. The default value is nobody 7 # user nobody; 8 9 # Number of enabled threads, generally consistent with the number of logical CPU cores 10 worker_processes 1; 11 12 # locate the global error log file, the level is displayed as notice, and debug, info, warn, error, crit mode, the most debug output, and the least crir output, depending on the actual environment. 13 # error_log logs/error. log; 14 # error_log logs/error. log notice; 15 # error_log logs/error. log info; 16 17 # storage file location of the specified process id 18 # pid logs/nginx. pid; 19 20 # specify the maximum number of file descriptors opened by an nginx process. The maximum number of opened files is 21 # worker_rlimit_nofile 65535 22 23 events {24 # Set the working mode to epoll. In addition, select, poll, kqueue, rtsig and/dev/poll modes 25 # use epoll; 26 27 # define the maximum number of connections for each process, which is limited by the maximum number of files opened by the system process. 28 worker_connections 1024; 29} 30 31 ####### Nginx Http server configuration, Gzip configuration 32 http {33 # master module command, setting the files contained in the configuration file can reduce the complexity of the master configuration file. The zonerfc1912 In the DNS master configuration file basically uses the include statement for the acl. 34 include mime. types; 35 36 # core module command. The intelligence is set to binary stream by default, that is, 37 default_type application/octet-stream is used when the file type is undefined; 38 39 # The following Code sets the log format. main is the name of the log format. You can set it as needed, reference 40 # log_format main' $ remote_addr-$ remote_user [$ time_local] "$ request" '41 # '$ status $ body_bytes_sent "$ http_referer" '42 #' "$ http_user_agent" "$ http_x_forwarded_for "'; 43 44 # reference log main 45 # access_log logs/access. log main; 46 47 # set to allow client requests The maximum number of bytes of a single file is 48 # client_max_body_size 20 M; 49 # specify the size of the headebuffer from the client request header to 50 # client_header_buffer_size 32 k; 51 # specify the directory path 52 # client_body_temp_path/dev/shm/client_body_temp for connection requests to write cached files; 53 # specify the maximum number and size of cached message headers in client requests, currently, it is set to 4 32KB 54 # large client_header_buffers 4 32 k; 55 56 # enable efficient File Transfer Mode 57 sendfile on; 58 # enable to prevent network congestion 59 # tcp_nopush on; 60 # enable to prevent network congestion 61 # tcp_nodelay on; 62 63 # Set the timeout time for saving client connection activities 64 # keepalive_t Imeout 0; 65 keepalive_timeout 65; 66 67 # Set the client request read timeout time 68 # client_header_timeout 10; 69 # Set the client request Body read timeout time 70 # client_body_timeout 10; 71 # Set the timeout time of the corresponding client 72 # send_timeout 73 74 #### HttpGZip module configuration 75 # httpGzip modules 76 # enable gzip compression 77 # gzip on; 78 # set the minimum number of page bytes that can be compressed 79 # gzip_min_length 1 k; 80 # apply for four memory units of 16 k as the compression result stream cache 81 # gzip_buffers 4 16 k; 82 # Set the version used to identify the http protocol. The default value is 1.1 83 # gzip_http_version 1.1; 84 # specify the gzip compression ratio, 1-9 the smaller the number, the smaller the compression ratio, and the faster the speed. 85 # gzip_comp_level 2; 86 # specify the compression type 87 # gzip_types text/plain application/x-javascript text/css application/xml; 88 # Add the front-end cache server to the gzip compressed page 89 # gzip_vary on; 90 91 ######### Nginx server Virtual Host Configuration 92 server {93 # listening port: 80 94 listen 80; 95 96 # setting host domain name 97 server_name localhost; 98 99 # Set the language code for access 100 # charset koi8-r; 101 102 # Set the virtual host access log storage path and log format as main103 # access_log logs/host. access. log main; 104 105 # set the basic information of the VM 106 location/{107 # Set the website root directory of the VM 108 root html; 109 110 # Set the web page 111 index index.html index.htm; 112} 113 114 404/404 # error_page .html; 115 116 # redirect server error pages to the static page/50x.html 117 #118 error_page 500 502 503 x.html; 504/50 location =/50x.html {119 root html; 121} 122 123 # proxy the PHP scripts to Apache listening on 127.0.0.1: 80124 #125 # locatio N ~ \. Php ${126 # proxy_pass http: // 127.0.0.1; 127 #} 128 129 # pass the PHP scripts to FastCGI server listening on 127.0.0.1: 9000130 #131 # location ~ \. Php ${132 # root html; 133 # fastcgi_pass 127.0.0.1: 9000; 134 # fastcgi_index index. php; 135 # fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name; 136 # include fastcgi_params; 137 #} 138 139 # deny access. htaccess files, if Apache's document root140 # concurs with nginx's one141 #142 # location ~ /\. Ht {143 # deny all; 144 #} 145} 146 147 148 # another virtual host using mix of IP-, name -, and port-based configuration149 #150 # server {151 # listen 8000; 152 # listen somename: 8080; 153 # server_name somename alias another. alias; 154 155 # location/{156 # root html; 157 # index index.html index.htm; 158 #} 159 #} 160 161 162 # HTTPS server163 #164 # server {165 # listen 443 ssl; 166 # server_name lo Calhost; 167 168 # ssl_certificate cert. pem; 169 # ssl_certificate_key cert. key; 170 171 # ssl_session_cache shared: SSL: 1 m; 172 # ssl_session_timeout 5 m; 173 174 # ssl_ciphers HIGH :! ANULL :! MD5; 175 # ssl_prefer_server_ciphers on; 176 177 # location/{178 # root html; 179 # index index.html index.htm; 180 #} 181 #} 182 183}
3. Nginx proxy website

A. I deployed a javaweb project under tomcat. the IP address of the server installed by tomcat is 192.168.37.136. The access address of the deployed project under tomcat is http: // 192.168.37.136: 8080/lywh/

B. I have successfully installed Nginx under the server whose IP address is 192.168.37.htm.

C. How can I use the Nginx proxy for the website deployed under tomcat ?, Modify the Nginx configuration file and run the command vim/usr/local/nginx/conf/nginx. conf.

1 # user nobody; 2 worker_processes 1; 3 # error_log logs/error. log; 4 # error_log logs/error. log notice; 5 # error_log logs/error. log info; 7 # pid logs/nginx. pid; 10 events {11 worker_connections 1024; 12} 15 http {16 include mime. types; 17 default_type application/octet-stream; 18 19 # log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request" '20 #' $ status $ body_bytes_sent "$ http_refe Rer "'21 # '" $ http_user_agent "" $ http_x_forwarded_for "'; 22 23 # access_log logs/access. log main; 24 25 sendfile on; 26 # tcp_nopush on; 27 28 # keepalive_timeout 0; 29 keepalive_timeout 65; 30 31 # gzip on; 32 33 # configure the tomcat IP address and access port 34 upstream gw {35 server 192.168.37.136: 8080 weight = 1; 36} 37 server {38 listen 80; 39 server_name localhost; 40 41 # charset koi8-r; 42 43 # access_log logs/host. acce Ss. log main; 44 45 location/{46 root html; 47 index index.html index.htm; 48} 49 # Nginx proxy configuration 50 location/lywh {51 proxy_pass http: // gw/lywh; 52} 53 location/sapi {54 proxy_pass http: // gw/shopappapi; 55} 56 location/cas {57 proxy_pass http: // gw/cas-server-webapp-4.0.0/login; 58} 59 location/doc {60 proxy_pass http: // gw/docs; 61} 62 63 # error_page 404/404 .html; 64 65 # redirect server Error pages to the static page/50x.html 66 #67 error_page 500 502 503 x.html; 68 location =/50x.html {69 root html; 70} 71 72 # proxy the PHP scripts to Apache listening on 127.0.0.1: 80 73 #74 # location ~ \. Php ${75 # proxy_pass http: // 127.0.0.1; 76 #} 77 78 # pass the PHP scripts to FastCGI server listening on 127.0.0.1: 9000 79 #80 # location ~ \. Php ${81 # root html; 82 # fastcgi_pass 127.0.0.1: 9000; 83 # fastcgi_index index. php; 84 # fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name; 85 # include fastcgi_params; 86 #} 87 88 # deny access. htaccess files, if Apache's document root 89 # concurs with nginx's one 90 #91 # location ~ /\. Ht {92 # deny all; 93 #}94} 95 96 97 # another virtual host using mix of IP-, name -, and port-based configuration 98 #99 # server {100 # listen 8000; 101 # listen somename: 8080; 102 # server_name somename alias another. alias; 103 104 # location/{105 # root html; 106 # index index.html index.htm; 107 #} 108 #} 109 110 111 # HTTPS server112 #113 # server {114 # listen 443 ssl; 115 # server_name loca Lhost; 116 117 # ssl_certificate cert. pem; 118 # ssl_certificate_key cert. key; 119 120 # ssl_session_cache shared: SSL: 1 m; 121 # ssl_session_timeout 5 m; 122 123 # ssl_ciphers HIGH :! ANULL :! MD5; 124 # ssl_prefer_server_ciphers on; 125 126 # location/{127 # root html; 128 # index index.html index.htm; 129 #} 130 #} 131 132}

D. After Nginx. conf is configured, close the file and run the command to check whether the configuration file is faulty. If yes, check whether the configuration is faulty.

    

E. Check if OK is returned, it means there is no error in modifying the file. Restart Nginx at this time. Command:/usr/local/nginx/sbin/nginx-s reload

F. The website after the last access to the proxy, http: // 192.168.37.htm/lywh, indicates that the website has been accessed by the Proxy:

    

 

This note has been written. If you have any questions, you can discuss it with me. I also write notes while learning. If there is any error, please let me know.

I wish you a happy New Year and a smooth journey tomorrow.

[Reprinted]

Chuxin MALL: chuxin mall

Author: Han Yinglong (Kencery) MVC/. NET group: 159227188
If you think this article is good or rewarding, you can use the "reward" function on the right to enjoy a cup of coffee. The copyright on this page is owned by the author and the blog Park. You are welcome to repost it, however, this statement must be retained without the author's consent and the original article link should be clearly provided on the article page; otherwise, the right to pursue legal liability will be retained.

Related Article

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.