Tag Archives: nginx

Troubleshooting of nginx error under Windows: createfile() “XXX / logs / nginx. PID” failed



Under windows, when we execute nginx -s stop or Nginx -s quit  or Nginx -s reload   You may receive the following error messages:

nginx: [error] CreateFile() "D:/software/nginx/logs/nginx.pid" failed (2: The system cannot find the file specified)


When we use start Nginx   To start Nginx xxx/logs/   Generated under the directory named   Nginx.PID   The content of the file has only one number, that is, the PID corresponding to the nginx.exe process. Whether stop, quit or reload, you need to use the PID of nginx.exe to operate it. However, in some special cases (we will create a special case artificially below), Nginx.PID will be lost, so the above three commands will report an error because Nginx.PID cannot be found. Obviously, it is impossible to stop, quit or reload successfully at this time, because nginx doesn’t even know which process it corresponds to.


Simple and rough: 1) pass tasklist | findstr “nginx.exe”   Find out the PID corresponding to nginx.exe; 2) In xxx/logs/   New text file under Nginx.pid  , Write the PID of the previous step through the text editor (of course, this step can also be carried out through command line, script, hands-on programming and other methods that can achieve the purpose); 3) Execute Nginx -s stop or Nginx -s quit   Or Nginx -s reload.



In this verification, the nginx installation path is   D:/software/nginx  , The listening port is 5000.

The rendering method is a command-line screenshot. The commands used will be given in the form of text in the back, which is convenient for readers to copy and paste.

This paper only focuses on the problem of “unable to find nginx. PID”. For other problems derived from the verification process, this paper only gives the link of the answer and does not guarantee the right remedy (it does not mean that the document content is wrong, but does not guarantee that the corresponding problem can be solved). I also urge readers who know the answer to give me advice.

The commands in the verification process must be executed under the nginx installation directory, otherwise an error will occur. If you have to execute in any directory, please refer to another blog under. At the same time, remember to make corresponding changes to the relevant path.

The verification process is shown in the figure below:

Verification process

The commands used are sorted as follows:

1 start nginx
2 tasklist | findstr "nginx.exe"
3 netstat -ano | findstr "5000"   
4 type ./logs/nginx.pid
5 nginx -s quit
6 cmd /r dir /b .\\logs
7 13632 | Out-File -Encoding ASCII ./logs/nginx.pid


Solve the 400 error of nginx forwarding websocket

Original address: https://www.cnblogs.com/duanweishi/p/9286461.html


Because there are multiple items on the personal server and the secondary domain name is configured, the secondary domain name needs to be forwarded. In the forwarding work, the famous nginx is adopted. Before that, there was no problem in forwarding all projects. However, when deploying a project with websocket communication, an unexpected error was reported. The error message is as follows:

1failed: Error during WebSocket handshake: Unexpected response code: 400

。 There is no problem with this error in the local test environment and accessing non nginx forwarding. Therefore, it is inferred that the problem should occur in nginx forwarding.

So, with the help of Google , I saw socket. IO   The official issues has a discussion on this issue, link: https://github.com/socketio/socket.io/issues/1942


After reading the scheme in the discussion area, the problem appears in the configuration file of nginx , and the nginx.conf file needs to be modified. In the linux terminal, type VIM/etc/nginx/nginx.conf , find the location , and the configuration file is as follows:

1server {
2        listen       80;
3        server_name  school.godotdotdot.com;
4        charset utf-8;
6        location/{
7            proxy_pass;
8            proxy_set_header Host $host;
9            proxy_http_version 1.1;
10            proxy_set_header Upgrade $http_upgrade;
11            proxy_set_header Connection "upgrade";
12            proxy_set_header X-Real-IP $remote_addr;
13            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
14            proxy_connect_timeout 60;
15            proxy_read_timeout 600;
16            proxy_send_timeout 600;
17        }
19        error_page   500 502 503 504  /50x.html;
20        location = /50x.html {
21            root   html;
22        }
24    }

The most important of these are the following three lines

1proxy_http_version 1.1;
2proxy_set_header Upgrade $http_upgrade;
3proxy_set_header Connection "upgrade";

The first line tells nginx to use the http/1.1 communication protocol, which must be used by websoket .

The second and third lines tell nginx to respond to the HTTP upgrade request when it wants to use websocket.


Nginx error 111: connection rejected [How to Solve]

Recently, I encountered nginx crazy throwing errors. There are more than 5W entries in access.log a day, but there are about 9K entries in error.log, which are basically 111: connection rejected . Why

From the log

Let’s look at the log first. I extracted a log of errors thrown in the error.log (divide it into one line slightly, otherwise it is too long, and handle the sensitive information slightly):

2019/06/06 10:09:45 [error] 28652#0: *883239 connect() failed (111: Connection refused) while connecting to upstream, 
client:, server: xxx.xxxxx.com, request: "POST /test-service/upload?mcachenum=155978698 HTTP/1.1", 
upstream: "http://[::1]:17000/test-service/upload?mcachenum=155978698", host: "xxx.xxxxx.com", 
referrer: "https://servicewechat.com/x98b46f69/2/page-frame.html"

After looking at the error report in front and the description in the back, it seems normal at first glance. But after looking again, I found that the host in upstream is somewhat different [:: 1] , which is actually an IPv6 address


At this time, you can check whether your machine has IPv6 address enabled. The command of Linux is: IP address , and see if inet6 appears in the returned result. If so, congratulations. The reason has been found


There are two solutions. One is to disable the IPv6 configuration of your machine, and the other is to modify the configuration in nginx.conf

Personally, I think the latter method is safer because it does not involve your machine configuration and should be relatively least

The modification of nginx.conf is to modify proxy for location in the server module_The host in pass , which we often see on the Internet, is:

proxy_pass http://localhost:18000/test -service/;

However, in order to forcibly specify the IPv4 address, it needs to become:

proxy_pass -service/;


After this operation, observe the error.log of nginx, and there should be no more IPv6 address errors in upstream


The above is the whole process of my mistake. Although the whole process is not long, it does let me know that as a back-end development, my knowledge is still too narrow. And Bing is really easy to use. I can’t climb the wall recently. It’s good to use Bing instead for the time being

Error 500 when opening the site configured by nginx

500 minutes


1. Site directory structure






2 nginx

listen 80;
server name test.aa.com
index index.html index.php default.html default.html default.php;




fastcgi param php admin value“open basedir=$document root/:/tmp/:/proc/:/data/wwwroot/”;

Note: add red part

[Solved] Nginx 502Bad Gateway: some static resources cannot be accessed

Scenario: Currently, there are several node services in ECs, using the forever process to guard. Recently, I opened the online page and found an error 502 bad gateway ; At the same time, some static resources cannot be accessed. (previously available)

first view the log information of nginx, which is basically repeated as follows

2017/04/25 22:09:45 [warn] 25037#0: *12 an upstream response is buffered to a temporary file /usr/local/nginx/proxy_temp/3/00/0000000003 while reading upstream, client:, server: channel.zhaoleilei.cn, request: “GET /build/common.js HTTP/1.1”, upstream: “ “, host: “channel.zhaoleilei.cn”, referrer: “ http://channel.zhaoleilei.cn/login ”
2017/04/25 22:09:54 [info] 25037#0: *12 client prematurely closed connection while sending to client, client:, server: channel.zhaoleilei.cn, request: “GET /build/common.js HTTP/1.1”, upstream: “ “, host: “channel.zhaoleilei.cn”, referrer: “ http://channel.zhaoleilei.cn/login ”

Internet search for reasons, failed. Feel that the problem lies in nginx or forever; When opening nginx. Conf to try to modify the configuration, an error is found e514: write error (file system full?); Find the reason and say the disk is full. Check Ubuntu disk space and solve the problem with full processing method


Conclusion: the reason for this problem is that the temporary log of forever is too large, resulting in the disk full. Delete the log.

Expansion: do scheduled task log cutting, do compressed backup in days (which can be realized through script), keep it for a certain time for viewing, and do log analysis if necessary

Enable nginx and report an error. Port 80 is occupied

Recently, nginx was running on the local computer, and an error was reported after startup. It is suspected that port 80 is occupied

netstat -ano|findstr

Try 1: after checking, it is found that the port is occupied by a program with system PID 4. I tried to end the system in Explorer, and then the blue screen

I use it later http://localhost After accessing, it is found that it jumps to the IIS interface

Try 2: disable IIS: right click “my computer” – & gt“ Management “- & gt“ Services “- & gt“ Services and Applications “- & gt“ “IIS” disables IIS in the IIS panel, and the result still does not work

Now use http://localhost You will not jump to the IIS home page in the future. It is proved that port 80 is no longer used by IIS, but my nginx still can’t start


Try 3: I inquired about NT kernel & amp; System, try running the following command to shut down the HTTP service

C:\WINDOWS\system32>net stop http  
C:\WINDOWS\system32>netstat -ano | findstr  
C:\WINDOWS\system32>sc config http start=disabled  

Go to “services” and find world wide   Web publishing service, select disable

Restart the computer and start nginx. This time it succeeded, but I can still see the system program running in the task manager. It has not been turned off, but 80 is no longer occupied, and nginx has been started successfully


In fact, I don’t think this is so simple. Later, I found that 80 is no longer occupied. It is automatically changed to port 445. Run the following command to query port 445

netstat -ano|findstr

It turns out that 445 has been occupied


Later, if I want to restart IIS on port 80, I think there will be a problem. I didn’t try, but I think so. Some reference links are attached



nginx connect() failed (111: Connection refused) while connecting to upstream

With multi-dimensional model as the core, let the factory digital transformation and upgrading “within reach”>>>

After the company’s website moved to the new server, it was found that the site could not be accessed. There was a prompt 502 in the network. After checking the relevant server configuration, it felt that there was no problem. After testing, it was found that non PHP files such as TXT, HTML, etc. could be accessed directly, that is, PHP could not be accessed. It was preliminarily concluded that PHP FPM was not installed or started

first of all, judge whether PHP FPM has been installed. If not, you need to install PHP FPM first. You can install parameters related to PHP FPM< after confirming that PHP FPM has been installed on the server, check whether it has been started or restarted directly: after the server is installed, check whether it has been started[ [email protected] /]#/ usr/local/PHP/SBIN/PHP FPM start
after startup, restart nginx:

after startup[ [email protected] /]#Service nginx restart

and then refresh the website page, but it didn’t succeed, It’s still wrong

at this time, we first check the error log error.log, and find that there are all the same error reports:

connect() failed (111: connection reused) while connecting to upstream fastcgi:// : 9000…

the prompt means that port 9000 can’t be connected, which is strange. In fact, in the server configured with nginx, Most of them should be configured with as the distribution port< now we need to check whether there is a monitoring port: we need to check whether there is a monitoring port[ [email protected] /]#Netstat – ant | grep 9000 found that it did not listen, but in fact our PHP FPM has been started, so what should we do now< let’s check the configuration in php-fpm.conf: [ [email protected] /]#VIM/usr/local/PHP/etc/PHP FPM. Conf
find listen:

& lt; value name=”listen_ address”>/ tmp/php-cgi.sock</ value>

at this time, we need to make corresponding modification according to the listen address of the configuration file:

location ~ \. PHP ${
fastcgi_ pass;
fastcgi_ index index.php;
fastcgi_ param SCRIPT_ FILENAME $document_ root$fastcgi_ script_ name;
include fastcgi_ params;< }
changed to:

location ~ \. PHP ${
fastcgi_ pass unix:/tmp/php-cgi.sock;
fastcgi_ index index.php;
fastcgi_ param SCRIPT_ FILENAME $document_ root$fastcgi_ script_ name;
include fastcgi_ params;

Restart nginx. The visit was successful<
– –
Author: ljihe
source: CSDN
original text: https://blog.csdn.net/ljihe/article/details/78025133
Copyright notice: This article is the original article of the blogger, please attach the blog link if you reprint it

[Solved] When PostgreSQL writes data to Excel, there is a failure your, nginx error handling

Today’s development colleagues read the data from PostgreSQL and wrote it to excel. Due to the large amount of data, the development colleagues wrote the code that was not good enough and the speed was too slow, so there was a problem. I found the following information and modified the configuration of nginx to solve this problem. The detailed errors are as follows:

An error occurred.

Sorry, the page you are looking for is currently unavailable.

Please try again later.
If you are the system administrator of this resource then you should check theerror log for details.
Faithfully yours, nginx.


Change localhost in nginx configuration file to IP


Modify the hosts file and add localhost

    proxy_pass http://localhost:8080  # change to

Set connection time

proxy_ connect_ timeout 300; # The connection timeout between nginx and back-end server (proxy connection timeout)
proxy_ send_ timeout 300; # Back end server data return time (proxy sending timeout)
proxy_ read_ timeout 600; # After successful connection, the response time of back-end server (proxy receiving timeout)

is shorter

After modifying the configuration file, reload the configuration file

nginx -s reload

Solve the problem of using nginx failed to load resource: Net:: err_ INCOMPLETE_ CHUNKED_ Encoding problem

After chopping hands, the fraud call came before the express delivery was received. How to improve the privacy and security of e-commerce>>>

solve the problem of using nginx failed to load resource: Net:: err_ INCOMPLETE_ CHUNKED_ Encoding questions

Reference article:

(1) Solve the problem of using nginx failed to load resource: Net:: err_ INCOMPLETE_ CHUNKED_ Encoding problem

(2) https://www.cnblogs.com/aoxueshou/p/11764871.html

Let’s make a note.