install
Download installation packages and dependencies
Enter in browser http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz Ready to download
Download the installation package of nginx
http://nginx.org/en/download.html
install
- Tar – xvf pcre-8.37.tar.gz extract the compressed file
- Enter the pcre-8.37 directory and execute the. / configure command
- Install openssl, zlib, gcc dependencies
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
- Installing nginx
Use the command to unzip the nginx installation package and enter the nginx installation package directory - After executing the. / configure command, execute the make & & make install command
- Enter the / usr/local/nginx/sbin directory to start nginx and use the. / nginx command
- adopt http://ip/ Access, which indicates that it can be started successfully
- Close nginx and use the. / nginx -s stop command
- Reload nginx using. / nginx -s reload command
Configuration file for nginx
nginx.conf file under cd /usr/local/nginx/conf /
Content in configuration file
It contains three parts
- Global block: a configuration instruction that configures the overall operation of the server
Like worker_processes 1; Configuration of processing concurrency - events block: affects the network connection between the Nginx server and the user
Like worker_connections 1024; The maximum number of connections supported is 1024 - http block
It also includes two parts:
http global block
server block
Reverse proxy configuration
- Listen to the port. If you listen, turn to another port
Listen to port 80 and turn to port 8080
visit http://192.168.64.123:80 Forward request to http://192.168.64.123:8080/
server { listen 80; # Listening port server_name localhost; #Monitor ip #charset koi8-r; #access_log logs/host.access.log main; location / { root html; proxy_pass http://192.168.64.123:8080/; # Proxy address index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # 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; #} }
- Jump to services on different ports according to the access path
nginx listening port is 9001,
visit http://192.168.64.123:9001/edu/ Jump directly to http://192.168.64.123:8081/edu/
visit http://192.168.64.123:9001/vod/ Jump directly to http://192.168.64.123:8080/vod/
to configure
server { listen 9001; #listen somename:8080; server_name 192.168.64.123; location ~ /edu/ { proxy_pass http://192.168.64.123:8081; } location ~ /vod/ { proxy_pass http://192.168.64.123:8080; } }
location ~ /vod / regular expression description in configuration
- =: before using for URIs without regular expressions, the request string and the uri must match strictly. If they match
If successful, stop the drill down and process the request immediately. - ~: used to indicate that the uri contains regular expressions and is case sensitive.
- ~*: used to indicate that the uri contains regular expressions and is case insensitive.
- ^~: ask the Nginx server to find the identification uri and request word before using it for URIs without regular expressions
After the location with the highest string matching degree, the request is processed immediately with this location instead of using the regular uri in the location block to match the request string.