PCB 利用nginx正向代理实现上网

在PCB行业中,为了保证服务器的安全性,服务器正常都是需要与外网断开的,如果想在服务器通过浏览器下载一点东西是不行。通常作法是在一台可以上网的电脑下载文件,接着放到网络盘上,再从网络盘拷贝到服务器上。而另一种方式是用浏览器代理的方式实现上网,,这里介绍使用nginx正向代理实现上网.

 

一.查找DNS服务器IP

        nginx正向代理时配置用

       

       

 二.修改nginx.conf配置文件

       

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    
    server {
        #正向代理DNS服务器IP  CMD=> ipconfig/all 来查看
        resolver 192.168.203.9;
        #正向代理超时时间
        resolver_timeout 5s;
        #监听端口
        listen       8999;
        location / {
            # 配置正向代理参数
            proxy_pass $scheme://$host$request_uri;
            # 解决如果URL中带"."后Nginx 503错误
            proxy_set_header Host $http_host;
            # 配置缓存大小
            proxy_buffers 256 4k;
            # 关闭磁盘缓存读写减少I/O
            proxy_max_temp_file_size 0;
             # 代理连接超时时间
            proxy_connect_timeout 30;
            # 配置代理服务器HTTP状态缓存时间
            proxy_cache_valid 200 302 10m;
            proxy_cache_valid 301 1h;
            proxy_cache_valid any 1m;
        }
        
        #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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
View Code

三.启动nginx.exe并本机打开Web网页

      查看nginx Web应用是否正常

http://192.168.204.158:8999/

 四.浏览器代理设置

        nginx代理不支持https

posted @ 2018-12-17 19:03  pcbren  阅读(1215)  评论(0编辑  收藏  举报