nginx installation and simple use

Nginx is a reverse proxy server. Let's first understand the forward proxy and reverse proxy. Their corresponding roles are actually different.

Forward proxy: For example, if I want to use a PC to access google, it is impossible for us to achieve this because of a certain wall in China. At this time, we have to detour abroad and seek a proxy. This proxy may be a vpn, or it may be directly It is a vps built by myself. Finally, I access the google website through this proxy. The process here is that the PC machine passes through the proxy, and the proxy helps me to request google.com. This is the forward proxy, as shown below;


Reverse proxy: For example, when we visit Baidu, there may be thousands of servers behind this Baidu address serving us. You don't know which one is, and you don't need to know. You only need to know the server of this reverse proxy. Now, this reverse proxy server will forward the request to the real server, which is the reverse proxy, as shown below;



Practice nginx with windows

1. 下载nginx:https://nginx.org/en/download.html

2. Unzip, enter the root directory, modify config/nginx.conf, and add two servers (usually nginx will come with a server with port 80)

    server {
        listen       8090;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            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;
        #}
    }
	
    server {
        listen       8091;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   D:\Tools\webstorm\workspace\element-ui-admin\dist;
            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;
        #}
    }


3. Double-click nginx.exe to start, visit http://localhost:8090/, http://localhost:8091/#/







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324601964&siteId=291194637