Installation and simple use of nginx in Linux


Download installation packages and dependencies

Enter in browser Ready to download
Download the installation package of nginx


  1. Tar – xvf pcre-8.37.tar.gz extract the compressed file
  2. Enter the pcre-8.37 directory and execute the. / configure command
  3. Install openssl, zlib, gcc dependencies
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
  1. Installing nginx
    Use the command to unzip the nginx installation package and enter the nginx installation package directory
  2. After executing the. / configure command, execute the make & & make install command
  3. Enter the / usr/local/nginx/sbin directory to start nginx and use the. / nginx command
  4. adopt http://ip/ Access, which indicates that it can be started successfully
  5. Close nginx and use the. / nginx -s stop command
  6. 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

  1. Listen to the port. If you listen, turn to another port
    Listen to port 80 and turn to port 8080
    visit Forward request to
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;  # 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
    #location ~ \.php$ {
    #    proxy_pass;

    # pass the PHP scripts to FastCGI server listening on
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass;
    #    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;
  1. Jump to services on different ports according to the access path
    nginx listening port is 9001,
    visit Jump directly to
    visit Jump directly to
    to configure
server {
    listen       9001;
    #listen       somename:8080;

    location ~ /edu/ {
    location ~ /vod/ {

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.

Tags: Linux CentOS Nginx

Posted on Sat, 06 Nov 2021 11:43:38 -0400 by ThisIsMyName