随笔:Linux下 Nginx、ftp 配合使用乱码、403 问题记录

场景:

Linux 下安装了nginx、ftp,使用nginx代理ftp_dir目录访问文件出现乱码、403 forbidden问题。
nginx 的配置:

#user  root;
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;
    client_max_body_size 200m;

    #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;
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    server {
        listen   8071;
        server_name  localhost;
        ### 注意此处配置出现了 乱码
	   #charset utf-8;
		
	location / {
		root   /fs/apache-tomcat-8.5.35/webapps/hcweb/dist/;
		index  index.html index.hvtm;
        }

	location /ftp_dir/ {
            root   /home ;
	    index  index.html index.htm;
        }
		
        location /hcsys {
            proxy_pass http://10.8.4.188:8070/hcsys/;
		proxy_redirect off;
		proxy_set_header Host $host:8071;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }
		
	location /hcgis {
            proxy_pass http://10.8.4.188:8070/hcgis/;
	    proxy_set_header Host $host:8071;
        }
		
	location /hcprodct {
            proxy_pass http://10.8.4.188:8070/hcprodct/;
	    proxy_set_header Host $host:8071;
        }

	location /hctranscode {
            proxy_pass http://10.8.4.188:8070/hctranscode/;
	    proxy_set_header Host $host;
        }

	location /fs_alarm {
            proxy_pass http://10.8.4.188:8090/fs_alarm/;
	    proxy_set_header Host $host:8071;
        }

	location /max-activiti {
            proxy_pass http://10.8.4.188:8070/max-activiti/;
	    proxy_set_header Host $host;
        }
	location /core {
            proxy_pass http://10.8.4.186:8188/core/;
	    proxy_set_header Host $host;
        }	
    }

    # 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;
    #    }
    #}

}

一、乱码:

访问:http://10.8.4.188:8071/ftp_dir/Trans_Result/20d452be-5eff-4077-b9b5-a3463cc84307.html(该链接为我项目中的链接地址,供参考)
时出现乱码。
原因:
1、html 的编码为GBK


2、nginx.conf 中配置的为 utf-8,统一即可

    server {
        listen   8071;
        server_name  localhost;
        ### 注意此处配置出现了 乱码
	   #charset utf-8;

二、403 forbidden

访问:http://10.8.4.188:8071/ftp_dir/Trans_Result/20d452be-5eff-4077-b9b5-a3463cc84307.html(该链接为我项目中的链接地址,供参考)
原因:文件没有权限。
解决:

chmod -R 777 指定文件

附:
ftp上传文件失败,ftp_dir 目录权限。

403 问题解决:https://blog.csdn.net/onlysunnyboy/article/details/75270533

你可能感兴趣的:(随笔)