Nginx main configuration parameters detailed, nginx configuration website

Source: Internet
Author: User
Tags cas sendfile

Install Nginx in A.linux. The post address is: http://www.cnblogs.com/cindy-cindy/p/6847499.html

B. When the Nginx installation is complete, there will be a corresponding installation directory, the installation directory of the NGINX.CONFG is nginx main configuration file, nginx main configuration file is divided into 4 parts, main (global configuration), server (host configuration), upstream ( Load balancer server settings) and location (URL matches settings at specific locations), the four relationships are: Server Inherits Main,location inheritance Server,upstream does not inherit other settings or inherit.

C.nginx is a proxy server, under normal circumstances, the site can not be deployed under Nginx, such as Java-developed Javaweb program, we deployed under Tomcat, and then use the Nginx Proxy to point to Tomcat.

2.nginx.conf configuration file details (with notes)
  1 # kencery Comment description nginx file 2 # Time: 2016-1-19 3 # Learning content, just from the Internet, there are copyright issues please contact me to delete.     4 5 ######## Nginx Main (global configuration) file 6 #指定nginx运行的用户及用户组, the default is nobody 7 #user nobody;    8 9 #开启的线程数, generally consistent with the number of logical CPU cores worker_processes 1; Each of the #定位全局错误日志文件, the level of notice display, there are Debug,info,warn,error,crit mode, the debug output of the most, crir output minimum, according to the actual environment of the #error_log logs/ Error.log; #error_log Logs/error.log Notice; #error_log Logs/error.log Info; #指定进程id的存储文件位置 #pid Logs/nginx.pid; #指定一个nginx进程打开的最多文件描述符数目, limited by the maximum number of open files for the system process #worker_rlimit_nofile 65535 events {#设置工作模式为epoll, in addition to There are Select,poll,kqueue,rtsig and/dev/poll models #use epoll; #定义每个进程的最大连接数, limited by the maximum number of open files for the system process. Worker_connections 1024; ###### #Nginx的Http服务器配置, gzip configured with HTTP {#主模块指令, setting the files contained in the configuration file can reduce the complexity of the master profile, the Zonerfc1912,acl in the DNS master configuration file Basically, the include statement is used. Mime.types include; #核心模块指令, intelligence is set to binary stream by default, that is, when the file type is undefined, use this method Default_type Application/octet-streAm #下面代码为日志格式的设定, Main is the name of the log format, can be set by itself, followed by #log_format main ' $remote _addr-$remote _user [$time _local] "$re "Quest" $status $body _bytes_sent "$http _referer" $http _user_agen T "" $http _x_forwarded_for "; #引用日志main #access_log Logs/access.log Main; #设置允许客户端请求的最大的单个文件字节数 #client_max_body_size 20M; #指定来自客户端请求头的headebuffer大小 #client_header_buffer_size 32k; Wuyi #指定连接请求试图写入缓存文件的目录路径 #client_body_temp_path/dev/shm/client_body_temp; #指定客户端请求中较大的消息头的缓存最大数量和大小, currently set to 4 32KB #large client_header_buffers 4 32k; #开启高效文件传输模式 sendfile on; #开启防止网络阻塞 #tcp_nopush on; #开启防止网络阻塞 #tcp_nodelay on; #设置客户端连接保存活动的超时时间 #keepalive_timeout 0; Keepalive_timeout 65; #设置客户端请求读取超时时间 #client_header_timeout 10; #设置客户端请求主体读取超时时间 #client_body_timeout 10;     #用于设置相应客户端的超时时间 #send_timeout, #HttpGZip模块配置 #httpGzip modules #开启gzip压缩 77 #gzip on; #设置允许压缩的页面最小字节数 #gzip_min_length 1k; #申请4个单位为16K的内存作为压缩结果流缓存 Bayi #gzip_buffers 4 16k; #设置识别http协议的版本, the default is 1.1 #gzip_http_version 1.1; #指定gzip压缩比, the smaller the 1-9 number, the smaller the compression ratio, the faster the #gzip_comp_level 2; #指定压缩的类型 #gzip_types text/plain application/x-javascript text/css application/xml;   #让前端的缓存服务器进过gzip压缩的页面 #gzip_vary on;          ######## #Nginx的server虚拟主机配置 94 Listen 80; 95 96 #设置主机域名 server_name localhost; 98 #设置访问的语言编码100 #charset koi8-r;101 102 #设置虚拟主机访问日志的存放路径及日志的格式为main103 #acces             S_log logs/host.access.log main;104 #设置虚拟主机的基本信息106 location/{107 #设置虚拟主机的网站根目录108 Root html;109 #设置Web page default access by Virtual Host 111 index index.html index.htm;112}113 #error_page 404/404.htm L;115 # REDIRECT Server error pages to the static page/50x.html117 #118 error_page 500 502 503 504/50x.html;119 location =/50x.html {root html;121}122 123 # Proxy The   PHP scripts to Apache listening on 127.0.0.1:80124 #125 #location ~ \.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$ {html;133 # root # Fastcgi_pass 127.0.0.1:9000; 134 # Fastcgi_index index.php;135 # Fastcgi_param script_filename/scripts$fastcgi_script_name;13 6 # include fastcgi_params;137 #}138 139 # Deny access to. htaccess files, if Apache ' s D         Ocument root140# concurs with Nginx ' s one141 #142 #location ~/\.ht {143 # deny all;144 #}145}14     6 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 L ocalhost;167 168 # ssl_certificate cert.pem;169 # ssl_certificate_key cert.key;170 171 # Ssl_se Ssion_cache shared:ssl:1m;172 # ssl_session_timeout 5m;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, with the server IP of Tomcat installed: 192.168.37.136, the access address of the deployed project under Tomcat is: http://192.168.37.136:8080/lywh/

B. I installed the 192.168.37.133 under the IP server.

C. How about using the Nginx proxy for sites deployed under Tomcat? , modify the Nginx configuration file, modify 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; Ten events {One worker_connections, and a. http {include mime.types; Default_type applicat Ion/octet-stream; #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; #tcp_nopush on; #keepalive_timeout 0; Keepalive_timeout 65; #gzip on;     #配置tomcat的IP地址和访问端口 upstream GW {192.168.37.136:8080 weight=1;   * * * PNS server {Listen, server_name localhost, 42 #charset koi8-r; #access_log logs/host.access.log main; The location/{root HTML; index index.html index.htm; #N Ginx Agent configuration of LOCATION/LYWH {Proxy_pass http://gw/lywh; The HTTP://GW/SHOPAPPAPI; location/cas{Proxy_pass Http://gw/cas-server-webapp-4.0.0/login, location/do c{proxy_pass Http://gw/docs; #error_page 404/404.html;  # REDIRECT Server error pages to the static page/50x.html 500 502 503 504/50x.html; The location of the location =/50x.html {The root html;] The PHP scripts to Apach          E listening on 127.0.0.1:80 # #location ~ \.php$ {# Proxy_pass http://127.0.0.1; 76 #} * * * Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 79        # #location ~ \.php$ {Bayi # root HTML; Fastcgi_pass 127.0.0.1:90 00; Fastcgi_index # index.php; # Fastcgi_param Script_filename/scripts$fastcgi_script_name; # include Fastcgi_params;  * #} * * * * * # Deny access to. htaccess files, if Apache ' s document Root # concurs with Nginx ' s One # #location ~/\.ht {* * * * deny all; 94} * * Anothe R Virtual host using mix of ip-, name-, and port-based Configuration 98 # #server {80 # Listen 00;101 # Listen somename:8080;102 # server_name somename alias another.alias;103 104 # Locat  Ion/{html;106 # root # index index.html index.htm;107 #}108 #}109 110 111 # HTTPS server112 #113 #server {Listen # 443 ssl;115 # server_name  localhost;116 117 # ssl_certificate cert.pem;118 # ssl_certificate_key cert.key;119 # SSL _session_cache shared:ssl:1m;121 # ssl_session_timeout 5m;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. When you are finished configuring nginx.conf, close the file, execute the command to check the configured file for problems, if it is not a problem, you need to check the configuration for problems

    

E. Check if return OK, the modification file does not have any errors, this time restart Nginx, the command is:/usr/local/nginx/sbin/nginx-s Reload

F. The website after the last visit to the agent, HTTP://192.168.37.133/LYWH,: Indicates that the agent has visited:

    

This note has been written, if you have any questions to discuss with me, I am also learning while writing notes, such as where there are errors, please tell

Finally I wish you a happy New year, go home tomorrow, a smooth journey

Nginx main configuration parameters detailed, nginx configuration website

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.