1. 程式人生 > 實用技巧 >使用WinSCP上傳檔案到指定伺服器並配置nginx

使用WinSCP上傳檔案到指定伺服器並配置nginx

安裝WinSCP

首先,我們先去官網下載 WinSCP,點選下圖所示的下載即可。

新建站點

開啟 WinSCP,系統自動要求新建站點登入。
檔案協議選擇 SFTP,主機名填入自己伺服器的公網ip,埠號選擇 22。使用者名稱和密碼填入自己登入伺服器的使用者名稱和密碼。填寫完畢之後,點選登入。

登入完成之後,可以看到介面分成了左右兩側。左側介面是控制自己電腦檔案的,右側介面是控制自己伺服器檔案的。

傳輸檔案

比如上傳vue打包檔案,我們再左側本地目錄內找到打包之後的dist資料夾,右側開啟需要放打包檔案的資料夾。

第一步

第二步

配置nginx

但是呢,我們是上傳到伺服器了,但是我們還需要配置一下nginx轉發才可以公網進行訪問
我們在右側介面找到伺服器上nginx的安裝位置,比如我的在/etc/nginx檔案下

實現公網訪問

點開nginx.conf,進行編輯

主要操作

現在我們去登入我們的伺服器,找到 nginx安裝的所在資料夾,點選下圖箭頭指示的位置,開啟對話視窗

重啟nginx

./nginx -s reload

檢視專案

這個時候我們開啟瀏覽器,輸入自己伺服器的 ip 地址,就可以訪問到我們上傳的vue專案了。

域名轉發ip

阿里雲後臺連線起來,nginx配置
之前配置完整版(僅供參考)

內蒙測試伺服器

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

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

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
        client_max_body_size    20m;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;



    server {
         listen       81;
         server_name  localhost;

        

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                      root   /app/frontcode;
                      index  index.html index.htm;
        }
        location /NMPWgcgk/ {
            proxy_pass  http://47.104.17.68:8081/NMPWgcgkV1.0.4/;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
    
     server {
         listen       85;
         server_name  localhost;

        

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                      root   /app/hrsys/frontcode;
                      index  index.html index.htm;
        }
        location /api/ {
            proxy_pass  http://47.104.17.68:9091/hrsys/;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
    
    server {
        listen       82;
        server_name  localhost;
        
        location / {
            root   /app;
            index  index.html index.htm;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

       server {
        listen       80;
        server_name  www.tyjsta.com tyjsta.com;
        
        location / {
            proxy_pass  http://127.0.0.1:82/tyj/;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

      server {
        listen       80;
        server_name  www.kesust.com kesust.com;
        
        location / {
            root   /app/kesu;
            index  index.html index.htm;
            proxy_pass http://127.0.0.1:82/kesu/;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

    server {
        listen       80;
        server_name  www.drzlst.com drzlst.com;
        
        location / {
            root   /app/kesu;
            index  index.html index.htm;
            proxy_pass http://127.0.0.1:82/dairui/;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

     server {
        listen       80;
        server_name  www.qishst.com qishst.com;
        
        location / {
            root   /app/lwwb;
            index  index.html index.htm;
            proxy_pass http://127.0.0.1:82/lwwb/;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
        server {
        listen       84;
        server_name  localhost;
        
        location / {
            root   /app/lwwb;
            index  index.html index.htm;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }








# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}