P
P
piatachki2018-07-02 02:57:31
Nginx
piatachki, 2018-07-02 02:57:31

Why is there a redirect to example.com/@custom when trying to upload a file?

Hello.
There is a web application on the Java + Spring + Thymeleaf stack, it works on the built-in tomcat. When trying to submit a form with MultipartFile, it redirects to example.com/@custom with a 404 error, respectively.
Form code:

<form action="/user/change-avatar" method="post" enctype="multipart/form-data">
                            <div class="form-group">
                                <label for="avatar-field">Сменить аватар</label>
                                <div class="input-group">
                                    <input name="file" class="form-control" id="avatar-field" accept="image/jpeg" type="file">
                                    <div class="input-group-append">
                                        <button class="btn btn-secondary" type="submit">Загрузить</button>
                                    </div>
                                </div>
                            </div>
                        </form>

Since everything works on the local machine, I suspect the server configuration. Apache and nginx are on the server. The application works on port 8900, Apache (as I understand it) proxies port 80 to 8900. The apache configuration for the host is as follows:
<VirtualHost 185.22.***.***:8181>
  ServerName example.com
  ServerAlias www.example.com
  ServerAdmin [email protected]
  DocumentRoot /home/example.com/public_html
  UseCanonicalName Off
  ScriptAlias /cgi-bin/ /home/example.com/public_html/cgi-bin/

  # Custom settings are loaded below this line (if any exist)
  # Include "/usr/local/apache/conf/userdata/example.com/example.com/*.conf

  <IfModule mod_userdir.c>
    UserDir disabled
    UserDir enabled username
  </IfModule>

  <IfModule mod_suexec.c>
    SuexecUserGroup username username
  </IfModule>

  <IfModule mod_suphp.c>
    suPHP_UserGroup username username
    suPHP_ConfigPath /home/username
  </IfModule>

  <Directory "/home/username/public_html">
    AllowOverride All
  </Directory>

    ProxyPreserveHost on
    ProxyPass /.well-known !
    ProxyPass "/" "http://example.com:8900/" nocanon
    ProxyPassReverse "/" "http://example.com:8900"
    AllowEncodedSlashes On

    RewriteEngine On
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

</VirtualHost>

To be honest, I didn’t find the niginx configuration, and I don’t understand why it is needed - it’s very weak in this matter. Tell me, please, in which direction to dig.
UPD: plain text forms without enctype="multipart/form-data" submit normally
UPD 7.07: found the nginx config, but lost the relevance of the question - moved the backing to another host without apache|nginx, purely tomcat works there, the error disappeared. But it would still be interesting for the future.
# Virtual host file starts here

server {
listen 185.22.153.66:443;
access_log /var/log/nginx/access.example.com.log;
error_log /var/log/nginx/error.example.com.log;
server_name example.com www.example.com;
root /home/user/public_html;

ssl                  on;
ssl_certificate      /etc/pki/tls/certs/example.com.bundle;
ssl_certificate_key  /etc/pki/tls/private/example.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
ssl_prefer_server_ciphers   on;

ssl_session_cache   shared:SSL:20m;
ssl_session_timeout 60m;

add_header Strict-Transport-Security "max-age=31536000";
add_header X-Content-Type-Options nosniff;

location / {
location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|ttf|svg|eot|sh)\$ {
expires 7d; #Comment this out if you are using the apache backend cache-control/expires headers.
try_files \$uri \@backend;
}
error_page 405 = \@backend;
error_page 500 = \@custom;
add_header X-Cache "HIT from Backend";
proxy_pass http://185.22.***.***:8181;
include proxy.inc;
}
location \@backend {
internal;
proxy_pass http://185.22.***.***:8181;
include proxy.inc;
}
location \@custom {
internal;
proxy_pass http://185.22.***.***:8181;
include proxy.inc;
}
location ~ .*\.(php|jsp|cgi|pl|py)?\$ {
proxy_pass http://185.22.***.***:8181;
include proxy.inc;
}
location ~ /\.ht {
deny all;
}
}

# Virtual host file ends here

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zxscv, 2018-07-02
@zxscv

Since you have Apache on the front, you need to look for it in the nginx config, but most likely somewhere in the script. But in general, the strange configuration of Apache is on the front and nginx is in the backend

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question