使用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 {
#        }
#    }

}


服务器中的nginx

   #cd /tmp/nginx    //进入当前nginx文件夹
   #rpm -Uvh *.rpm    // 解压 压缩包
   #iptables -I INPUT -p tcp --dport 80 -j ACCEPT   //添加防火墙
   #service iptables save     //保存
   #service iptables restart   //重启
   #chkconfig nginx on     
   #service nginx restart   //重启nginx
原文地址:https://www.cnblogs.com/loveliang/p/13630594.html