Tag Archives: nginx

How to Solve Swagger error: typeerror: failed to fetch

Scene description

A project was recently deployed. Because it is compatible with IE8, the front and back ends need to be deployed to a site. The nginx configuration is as follows:

server {
    listen       80;
    server_name www.aaa.ink;
	client_max_body_size  1000M;
	client_body_timeout 20s;
	client_header_timeout 10s;
	send_timeout 30s;
	ssl_protocols TLSv1.2;
    charset utf-8;
	location ^~ /api/ {
		proxy_pass http://127.0.0.1:8080/api/;
	}
    
    location ~/(.*)$ {
        root   /usr/local/nginx/ttm;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

Swagger is used as the interface document in the background. After the project is started, the site can be accessed normally, but an error will be reported when testing the interface in swagger. The error prompt is typeerror: failed to fetch

Problem analysis

Analysis shows that swagger’s actual request address becomes http://127.0.0.1:8080/api/ , it’s not what we actually do http://www.aaa.ink/api/ Interface address. It is found that swagger will obtain a server address according to the user’s request. Due to the use of nginx reverse proxy, swagger obtained the intranet address we configured, resulting in the request unable to respond normally.

Problem solving

location ^~ /api/ {
	proxy_set_header Host $host;
	proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
	proxy_set_header X-Forwarded-Host $server_name;
	proxy_pass http://127.0.0.1:8080/api/;
}

Set the forwarding of background items to the request header so that swagger can get the real address. The problem can be solved.

ZK Error contacting service. It is probably not running [How to Solve]

A bug was encountered while recording the test

After initiating the request, return to 502 bad gateway (nginx/1.1.19) to check that nginx starts normally. After checking the back-end log, an error is found

java.net.ConnectException: Connection refused
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
	at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
	at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)

The error message shows that the Dubbo link and the zookeeper link are not available

Find the bin directory of zookeeper and use./zkserver.sh start to start normally
but when using./zkserver.sh status, an error is found in the error contacting service. It is probable not running

ZooKeeper JMX enabled by default
Using config: /opt/zk1/zookeeper-3.4.10/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.

Use the systemctl status ZK command to view the status (small gray dots)

● zk.service - Zookeeper Service
   Loaded: loaded (/etc/systemd/system/zk.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Mon 2021-10-11 20:17:54 CST; 2s ago
  Process: 9433 ExecStop=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh stop (code=exited, status=0/SUCCESS)
  Process: 9448 ExecStart=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh start (code=exited, status=0/SUCCESS)
 Main PID: 9458 (code=exited, status=1/FAILURE);         : 9485 (sleep)
    Tasks: 1
   Memory: 256.0K
      CPU: 3.695s
   CGroup: /system.slice/zk.service
           └─control
             └─9485 /bin/sleep 4
             
Oct 11 20:17:54 ubuntu systemd[1]: Starting Zookeeper Service...
Oct 11 20:17:54 ubuntu zkServer.sh[9448]: ZooKeeper JMX enabled by default
Oct 11 20:17:54 ubuntu zkServer.sh[9448]: Using config: /opt/zk1/zookeeper-3.4.10/bin/../conf/zoo.cfg
Oct 11 20:17:55 ubuntu zkServer.sh[9448]: Starting zookeeper ... STARTED
Oct 11 20:17:56 ubuntu systemd[1]: zk.service: Main process exited, code=exited, status=1/FAILURE

Attempt to start systemctl start ZK

Job for zk.service failed because the control process exited with error code. See "systemctl status zk.service" and "journalctl -xe" for details.

Check systemctl status ZK again

● zk.service - Zookeeper Service
   Loaded: loaded (/etc/systemd/system/zk.service; enabled; vendor preset: enabled)
   Active: activating (start-post) since Mon 2021-10-11 20:18:16 CST; 1s ago
  Process: 9894 ExecStop=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh stop (code=exited, status=0/SUCCESS)
  Process: 9910 ExecStart=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh start (code=exited, status=0/SUCCESS)
 Main PID: 9920 (java);         : 9953 (sleep)
    Tasks: 26
   Memory: 170.6M
      CPU: 3.268s
   CGroup: /system.slice/zk.service
           ├─9920 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,ROLLINGFILE -cp /opt/zk1/zookeeper-3.4.10/bin/../build/classes:/opt/zk1/zookeeper-3.4.10/bin/../build/lib/*.jar:/
           └─control
             └─9953 /bin/sleep 4

Oct 11 20:18:16 ubuntu systemd[1]: Starting Zookeeper Service...
Oct 11 20:18:16 ubuntu zkServer.sh[9910]: ZooKeeper JMX enabled by default
Oct 11 20:18:16 ubuntu zkServer.sh[9910]: Using config: /opt/zk1/zookeeper-3.4.10/bin/../conf/zoo.cfg
Oct 11 20:18:17 ubuntu zkServer.sh[9910]: Starting zookeeper ... STARTED

I still can’t find it
view the configuration file less zoo.cfg to find the log path

dataLogDir=/opt/zk1/zookeeper-3.4.10/datalog

Enter/opt/ZK1/zookeeper-3.4.10/datalog/version-2 and find a log suspected to be damaged (log. 220770)

-rw-r--r-- 1 root root 67108880 Sep 22 00:21 log.1ce8b6
-rw-r--r-- 1 root root 67108880 Sep 22 02:30 log.1e0dbe
-rw-r--r-- 1 root root 67108880 Sep 22 11:15 log.1e4a05
-rw-r--r-- 1 root root 67108880 Sep 22 20:26 log.1f407d
-rw-r--r-- 1 root root 67108880 Sep 23 02:30 log.20427c
-rw-r--r-- 1 root root 67108880 Sep 23 12:32 log.20ecc9
-rw-r--r-- 1 root root        0 Sep 23 12:33 log.220770

Delete this log RM log.220770 start again and check the status
systemctl start ZK systemctl status ZK (small green dot)

● zk.service - Zookeeper Service
   Loaded: loaded (/etc/systemd/system/zk.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2021-10-11 20:19:30 CST; 5s ago
  Process: 11032 ExecStop=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh stop (code=exited, status=0/SUCCESS)
  Process: 11088 ExecStartPost=/bin/sleep 4 (code=exited, status=0/SUCCESS)
  Process: 11047 ExecStart=/opt/zk1/zookeeper-3.4.10/bin/zkServer.sh start (code=exited, status=0/SUCCESS)
 Main PID: 11057 (java)
    Tasks: 28
   Memory: 222.5M
      CPU: 4.229s
   CGroup: /system.slice/zk.service
           └─11057 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,ROLLINGFILE -cp /opt/zk1/zookeeper-3.4.10/bin/../build/classes:/opt/zk1/zookeeper-3.4.10/bin/../build/lib/*.jar:

Oct 11 20:19:25 ubuntu systemd[1]: Starting Zookeeper Service...
Oct 11 20:19:25 ubuntu zkServer.sh[11047]: ZooKeeper JMX enabled by default
Oct 11 20:19:25 ubuntu zkServer.sh[11047]: Using config: /opt/zk1/zookeeper-3.4.10/bin/../conf/zoo.cfg
Oct 11 20:19:26 ubuntu zkServer.sh[11047]: Starting zookeeper ... STARTED
Oct 11 20:19:30 ubuntu systemd[1]: Started Zookeeper Service.

Restart the back-end service. The error is found and solved
in addition, there are other situations that can lead to this problem
1. The firewall is not closed
Ubuntu
CentOS
2. The port is occupied
netstat – ANP | grep port number
kill – 9 ID

ginx-1.10.0\index/**“ failed (123: The filename, directory name, orvolume label syntax is incorrect)

Nginx is used in Windows environment. Error log: ginx-1.10.0 \ index/static/JS/jquery-3.1.3. Min.js “failed (123: the filename, directory name, or volume label syntax is incorrect)”

The default path in windows is backslash \. My directory path just starts with n. It is estimated that it is interpreted as line feed, so you only need to add double slash \ or slash /,
H: \ nginx-1.10.0 \ nginx-1.10.0
positive solution:

H:\\nginx-1.10.0\\nginx-1.10.0

Or

H:/nginx-1.10.0/nginx-1.10.0/

Nginx Error: Swap file “/etc/nginx/.nginx.conf.swp“ already exists

The error information is as follows:

reason

In the process of writing, unexpected power failure, link failure, SSH client abnormal shutdown, etc. the server backed up the write operation, but did not write to the real file.

Editing a file with VIM is actually copying a temporary file and mapping it to memory for you to edit,   Editing is a temporary file,   Save the temporary file to the original file only after executing: W, and delete the temporary file only after executing: Q.

Each time you start editing, you will retrieve whether this file already exists as a temporary file,   If someone asks how to deal with it, the above situation will appear.

Workaround – delete temporary files

Select the temporary file path and right-click copy.

Enter Q again to exit

Delete temporary files. Execute the following command:

rm -rf /etc/nginx/.nginx.conf.swp

Redhat8 make nginx error reporting solution

1. Enter the objs folder and modify the makefile

Remove – werror, and the modification result is shown in the figure below

 

Error Src/OS/Unix/NGX_ user.c:26:7: error: ‘struct crypt_ data’ has no member named ‘current_ salt

Search current_ Salt, after commenting out this line, make & amp; make install

Browser Error: net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)

Browser error:

net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)

To view the Nginx error log:

13505#0: *1107085 pwritev() "/usr/local/nginx/proxy_temp/5/88/0000050885" failed 
(28: No space left on device) while reading upstream

There is not enough space, which means the disk is full.

Because proxy_Temp is the cache folder of Nginx. My CSS and JS files are too large, so Nginx usually takes them from the cache instead of directly loading them at the original address every time.

Refer to
browser error net:: err_ CONTENT_ LENGTH_ Mismach 200 (OK) solution

[Solved] Playbook Start Nginx Error: Unable to start service nginx: Job for nginx.service fd with error code

The error information is as follows:

TASK [start nginx service] *******************************************************************************************
fatal: [192.168.126.129]: FAILED! => {"changed": false, "msg": "Unable to start service nginx: Job for nginx.service fd with error code. See \"systemctl status nginx.service\" and \"journalctl -xe\" for details.\n"}

The reason is that the user/group I created for Nginx in playbook is user-defined:

Change it to Nginx:

nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open

Installation steps:

1. Download and install luajit 2.1 (both 2.0 and 2.1 are supported, and 2.1 is officially recommended): http://luajit.org/download.html

cd /usr/local/src
wget http://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz
tar zxvf LuaJIT-2.1.0-beta3.tar.gz
cd LuaJIT-2.1.0-beta2
make PREFIX=/usr/local/luajit
make install PREFIX=/usr/local/luajit

Solve the software startup error while loading shared libraries: libgd. So. 2: cannot open shared object error

This error is reported when installing and starting nginx today: error while loading shared libraries: libgd. So. 2: cannot open shared object. I checked the relevant information on the Internet and solved it. This record also allows friends who encounter this problem to solve it quickly.

First, let’s talk about the solution to help those who are anxious to solve the problem. This is because the GD library is missing. Just install it. Installation method: 1. It is easiest to directly Yum install GD . 2. If Yum can’t search the installation package of GD library, you can manually download the corresponding RPM package at: http://rpmfind.net/linux/rpm2html/search.php?query=libgd.so.2 Install after downloading.

After installation, start nginx normally.

Let’s talk about the troubleshooting steps. You can refer to this method to solve similar problems in the future.

According to the error prompt, the libgd. So. 2 class library file failed to load. In this case, either lib is not installed or the installation location is not in the correct location. Check the class library files that nginx depends on through the LDD command:

ldd /usr/local/nginx/sbin/nginx  
linux-vdso.so.1 =>  (0x00007fffd5fb6000)  
libpthread.so.0 => /lib64/libpthread.so.0 (0x000000379e200000)  
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x000000393f200000)  
libpcre.so.0 => /lib64/libpcre.so.0 (0x00000033d5800000)  
libssl.so.10 => /usr/lib64/libssl.so.10 (0x0000003c60200000)  
libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x0000003df9800000)  
libdl.so.2 => /lib64/libdl.so.2 (0x000000390be00000)  
libz.so.1 => /lib64/libz.so.1 (0x0000003a25600000)  
libc.so.6 => /lib64/libc.so.6 (0x0000003a24200000)  
libgd.so.2 => not found  
/lib64/ld-linux-x86-64.so.2 (0x0000003a23e00000)  
libfreebl3.so => /lib64/libfreebl3.so (0x000000393ea00000)  
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x000000379fa00000)  
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x000000379d200000)  
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x000000379e600000)  
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x0000003df9c00000)  
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x0000003dfa800000)  
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x0000003dfa400000)  
libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003a26a00000)  
libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003df7c00000)  

This is not found, libgd. So. 2 = & gt; not found

A search on the Internet shows that this library comes with the GD installation package. If you confirm that GD has been installed, then this library is on the system. Find this file through the find command

find/-name 'libgd.so.2'

After finding it, you can copy it to the corresponding lib directory. If not, you can only reinstall it. How do we know the name of the package to be installed?Very simple. You can baidu search libgd. So. 2 to find out which installation package the library file comes from. Or you can check this website, http://rpmfind.net/linux/rpm2html/search.php?query=libgd.so.2 , it is found that this class library is from the GD installation package

First

Yum search GD search. If yes, you can directly Yum install GD

It’s OK. If not, you can also find the installation package that conforms to your own system through the website above (mainly depending on the operating system version number, 32-bit or 64 bit, and the new version is 64 bit), download it, and then install it through the corresponding command. Other class library files are missing, and the solution is similar.

Interface request error 504 gateway time out [How to Solve]

This article mainly introduces the solution of page 504 gateway time-out

1. 504 gateway time out reason?

Because of the browser access interface request, the default timeout event is 1 minute. When the 504 interface timeout is encountered, first we need to see whether the Ajax interface request is set   Timeout. Next, check whether nginx has set the agent timeout.

2. Inspection procedure

1. Front end Ajax settings

$.ajax({
  url: '',
  type: 'post',
  data: postData,
  timeout: 1000*60*10,
  success: function(data){
    console.log(data)
  },
  complete:function(XHR,TextStatus){
    if(TextStatus=='timeout'){ 
      console.log("Timeout");
    }
  }
})

2. Nginx agent timeout setting

proxy_connect_timeout    600;
proxy_read_timeout       600;
proxy_send_timeout       600;
proxy_buffering    off;
proxy_buffer_size  128k;
proxy_buffers 100  128k;

3、 Problem extension (native JS encapsulates Ajax requests)

At that time, the Ajax request of jQuery was used, and the datatype: JSON was uniformly defined by the interface. Due to the file flow returned by the interface, the successful callback was not triggered and did not want to modify the datatype. Therefore, the Ajax request was encapsulated with native JS.

getAjax(url,callback){
    var timeoutFlag=null;
    var xhr=new XMLHttpRequest();
    var url=""//request path, get request can spell the parameters into the address
    xhr.open(type,url,async);//type request type url address async whether asynchronous request 
    xhr.responseType='blob';//If the return data is a file stream, you can set it to blob type
    xhr.timeout=1000*60*60;//timeout time This is set to one hour
    xhr.setRequestHeader('token',token);//set header token
    xhr.onreadystatechange=function(){
        if(xhr.readyState==4){
            window.clearTimeout(timeoutFlag);
            if(xhr.status==200 || xhr.status==304){
                callback(xhr.response);
            }
        }
    }
    xhr.send(data);
    timeoutFlag=window.setTimeout(function(){
        window.clearTimeout(timeoutFlag);
        xhr.abort();
    },xhr.timeout);
}
getAjax('URL',function(res){
})