This paper mainly describes the following points.
1, what is Nginx?
Nginx (engine x) is a lightweight Web server, reverse proxy server, and e-mail (IMAP/POP3) proxy server.
2, what is the reverse proxy?
The reverse proxy method refers to a proxy server that accepts connection requests on the Internet, then forwards the request to a server on the internal network and returns the results from the server to the client requesting the connection on the Internet, Reverse. At this point the proxy server appears as a reverse proxy server externally.
On the reverse proxy, there is a lot of information on the Internet to help understand.
3. Windows and Linux Installation
Simply say the installation on the window and add it later on Linux.
First: http://nginx.org/en/download.html
My current version is nginx/windows-1.10.2, find a location, unzip, to briefly explain the file directory under decompression:
The others do not introduce, say the main two files, conf is some configuration files, logs is some log files.
I unzipped the path is D:\YH, thought this path description, into the \nginx-1.10.2 folder, shift+ right mouse button, into the command window,
Here are a few more commands I use under window.
4, nginx commonly used a few commands
After entering the command window,start Nginx, you can start Nginx, do not rest assured? You can view it in task management.
After modifying the configuration file, need to re-reload, command is nginx-s Reload, this command is also very common, of course, there are other commands, as follows
Nginx - s stop quickly shuts down nginx, may not save relevant information, and quickly terminates the Web service.
Nginx - s quit smooth nginx, save the relevant information, there is scheduled to end the Web service.
Nginx - s reopen reopen the log file.
nginx-c filename Specifies a configuration file for Nginx instead of the default.
nginx-t does not run, but only tests the configuration file. nginx will check the correctness of the configuration file syntax and try to open the file referenced in the configuration file.
nginx-v Displays the version of Nginx.
nginx-v Displays nginx version, compiler version and configuration parameters.
Remember to use the command to start Nginx or re-reload, you can refer to logs several log files.
5, combined with the actual configuration of the project
In fact, I configured nginx just to complete the reverse proxy HTTP, there is no complex configuration, want to use their own configuration of the domain name to access my project "Discard localhost:9090", as for the use of Nginx load balancing, and so on after the configuration to the post of the supplement perfect.
The conf/nginx.conf configuration is as follows:
#运行的用户#user nobody;#启动进程, usually set to equal to the number of CPUsWorker_processes 1;#全局错误日志Error_log d:/yh/nginx-1.10.2/logs/error.log;error_log d:/yh/nginx-1.10.2/logs/notice.log Notice;error_log D:/yh/ Nginx-1.10.2/logs/info.log info;#PID文件, log the process ID of the nginx that is currently startedPID D:/yh/nginx-1.10.2/logs/nginx.pid;#工作模式及连接数上限Events {Worker_connections 1024;Maximum number of concurrent links #单个后台worker process processes}#设定http服务器, using its reverse proxy function to provide load balancing supportHTTP {#设定mime类型 (Message support type), type is defined by the Mime.types fileInclude D:/yh/nginx-1.10.2/conf/mime.types; Default_type Application/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 D:/yh/nginx-1.10.2/logs/access.log Main;#sendfile instruction Specifies whether Nginx calls the Sendfile function (zero copy mode) to output files, for normal applications, #必须设为 on, if used for downloading applications such as disk IO heavy-duty applications, can be set to off to balance disk and network I/O Processing speed, reducing the uptime of the system.Sendfile on; #tcp_nopush on;#连接超时时间#keepalive_timeout 0; Keepalive_timeout 120;#gzip压缩开关#gzip on;#设定实际的服务器列表Upstream server1{server 127.0.0.1:9090; }#HTTP服务器server {#监听80端口, Port 80 is a well-known port number for the HTTP protocolListen 80;#定义自己的访问url, there is a configuration in the hostsserver_name www.heyLuer.com;#首页Index index.html# project PathRoot D:\yh\workspace\xx\src\main\webapp;# Encoding FormatCharSet Utf-8;#代理配置参数Proxy_connect_timeout 180; Proxy_send_timeout 180; Proxy_read_timeout 180; Proxy_set_header Host $host; Proxy_set_header x-forwarder-for $remote _addr; #access_log Logs/host.access.log Main; Location/{Proxy_pass http://server1; }#错误处理页面 (optionally configurable)#error_page 404/404.html; #error_page 502 503 504/50x.html; #location =/50x.html {# root HTML; #} }}
Configuration as above, write very clear, Tomcat boot project, use domain name access, normal Access project, configure ok!
Because of the limited capacity, the above content if there are errors, you are welcome to correct.
Additional content to follow ...
Nginx Simple Configuration