Tag Archives: nginx

Nginx Startup Error: Job for nginx.service failed because the control process exited with error code. See …

Contact nginx for the first time. After installing and using the command service nignx restart , this error appears. Follow the command given in the prompt to view the error details systemctl status nginx. Service :

We can see from the details: (98: address already in use), which indicates that the port has been occupied. Let’s see what is occupying the port

Input command: netstat – apn|grep: 80

You can see that the 13929/httpd service occupies port 80 and needs to be shut down. (I tried to kill the process with kill, but it was invalid)

Execute the command: Service httpd stop to close the httpd service

Then restart niginx to start it

Nginx Error: Job for nginx.service failed because the control process exited with error code

Job for nginx.service failed because the control process exited with error code

View Status

systemctl status nginx.service

nginx.service – The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2021-01-15 20:18:19 CST; 2min 1s ago
Process: 439 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
Process: 437 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 436 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Jan 15 20:18:18 iZ2zehly2ejxq9dlkzklw9Z nginx[439]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 15 20:18:18 iZ2zehly2ejxq9dlkzklw9Z nginx[439]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 15 20:18:18 iZ2zehly2ejxq9dlkzklw9Z nginx[439]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 15 20:18:18 iZ2zehly2ejxq9dlkzklw9Z nginx[439]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 15 20:18:19 iZ2zehly2ejxq9dlkzklw9Z nginx[439]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 15 20:18:19 iZ2zehly2ejxq9dlkzklw9Z nginx[439]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 15 20:18:19 iZ2zehly2ejxq9dlkzklw9Z nginx[439]: nginx: [emerg] still could not bind()
Jan 15 20:18:19 iZ2zehly2ejxq9dlkzklw9Z systemd[1]: nginx.service: Control process exited, code=exited status=1
Jan 15 20:18:19 iZ2zehly2ejxq9dlkzklw9Z systemd[1]: nginx.service: Failed with result ‘exit-code’.
Jan 15 20:18:19 iZ2zehly2ejxq9dlkzklw9Z systemd[1]: Failed to start The nginx HTTP and reverse proxy server.

Problem

nginx: [emerg] bind() to 0.0.0.0:80 failed

 

Checking port 80 is occupied
kill pid

 

Restart nginx

systemctl start nginx.service

How to Solve Nginx Error 13: Permission denied) while connecting to upstream

When using nginx for load balancing, there is a problem

1 connect() to 10.51.2.237:8084 failed (13: Permission denied) while connecting to upstream, client: 10.51.2.237, server:

It has been confirmed that the local firewall has been shut down. After some inquiry, it is because of SELinux

SELinux is a mandatory access control (MAC) system provided in Linux kernel version 2.6. It’s a built-in security system, and firewalls should be external

So: there are two solutions

1. Close SELinux

1. Temporary shutdown (no need to restart the machine)

Setenforce 0 # set SELinux to permission mode

##Setenforce 1 sets SELinux to enforcing mode

2. To modify the configuration file, restart the machine

Modify/etc/SELinux/config file

Change SELinux = enforcing to SELinux = disabled

Just restart the machine

2. Execute the following command

setsebool -P httpd_ can_ network_ connect 1

[Solved] Nginx can’t listen to the problem of virtual VIP: 99: cannot assign requested address

99: Cannot assign requested address

#Without the IP 10.0.0.3 on the local NIC Nginx will report the following error.

[root@lb01 conf]# /application/nginx/sbin/nginx -t

nginx: the configuration file /application/nginx-1.10.2/conf/nginx.conf syntax is ok

nginx: [emerg] bind() to 10.0.0.3:80 failed (99: Cannot assign requested address)

nginx: configuration file /application/nginx-1.10.2/conf/nginx.conf test failed

[root@lb01 conf]# ip a s eth0

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    link/ether 00:0c:29:27:4e:e9 brd ff:ff:ff:ff:ff:ff

    inet 10.0.0.5/24 brd 10.0.0.255 scope global eth0

    inet6 fe80::20c:29ff:fe27:4ee9/64 scope link

       valid_lft forever preferred_lft forever

#Note: There is no way for nginx to listen to ip addresses that do not exist locally. 

solution to nginx monitoring virtual VIP: 

The above problem is that there is no IP corresponding to the IP monitored by the configuration file on the physical network card. The solution is to add the following kernel parameter configuration in/etc/sysctl.conf

echo 'net.ipv4.ip_nonlocal_bind = 1' >>/etc/sysctl.conf

sysctl -p# Effective 

#You can also make Nginx start up by ignoring the presence of VIPs listening in the configuration with the following method, also suitable for haproxy

echo "1" >/proc/sys/net/ipv4/ip_nonlocal_bind

Net:: err_ CONTENT_ LENGTH_ Mismatch error, nginx configuration is correct

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

Today is 16-12-01. Today, the mobile phone page of the project is going to be updated. All the codes were finished a few days ago. It’s just the data problem of the operation record. But suddenly around 10 a.m., the whole project can’t enter the front page. The error is as follows:

Not only this project, but also several projects using nginx as the reverse proxy, the front-end pages are inaccessible, while the back-end system interface is still as usual, so first of all, let’s conclude that nginx has a problem

1. Based on this problem, there are all solutions on the Internet, but almost the same is the issue of user permissions of nginx cache files

http://blog.csdn.net/oldcrane/article/details/46274189

Another reason is the firewall port problem

2. I tried for a long time, but I couldn’t solve my problem. So I thought that the project couldn’t work all of a sudden. If there was a problem with nginx configuration, it would not work before, so it shouldn’t be this problem. Since the project will be tested in the afternoon and the revision will be officially launched, the boss will also stare at it, so he is a little worried. Is it necessary to delete and reconfigure the entire nginx?Again, or such a mistake

3. Then I checked nginx again and wanted to upload the nginx.config configuration file again to see if it was OK. Suddenly, I found that there was an error in uploading the configuration file with SecureCRT RZ, and I couldn’t upload it. At this time, I felt that the configuration file had special garbled characters, but I couldn’t upload it with RZ – E

4. Is it a tool problem?So if you upload by SSH, or report an error , or upload by FTP, the upload is finally successful. Restart nginx, and report an error. Then view the VI configuration file, and find that the file content is only half, and the other half is gone?Looking at the uploaded local file, the content is complete

5. Here is the problem. Check the server disk

Visit the back-end application through nginx and report an error err_ CONTENT_ LENGTH_ MISMATCH

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

When using hue, it’s a bit slow to load CSS and other files, so we plan to use nginx to load local static files directly to achieve the purpose of acceleration. However, some pages can not be loaded, and the error net:: err will be reported_ CONTENT_ LENGTH_ MISMATCH。

In chrome, please cache or force refresh. The status code of response is 200

The status code of response is 206

In response header, the length of content length is consistent with the actual length of the target file

The above content length mismatch error will appear

If you do not access Tomcat directly through nginx, the system functions normally without this error

Solution:

After checking the error.log log of nginx, it is found that:

2016/08/25 09:59:52 [crit] 24677#0: *1 open() “/var/lib/nginx/tmp/proxy/1/00/0000000001” failed (13: Permission denied) while reading upstream, client: 182.148.107.206, server: 114.55.4.111, request: “GET /notebook/new HTTP/1.1″, upstream: ” http://114.55.4.111 :10081/notebook/new”,

It turns out that there is no permission. By default, nginx uses the directory created by the nginx user. I use the hue user here, so I have to give the permissions of the folder under nginx to hue

sudo chmod -R 775 /var/lib/nginx/
sudo chown -R hue /var/lib/nginx/

Restart nginx and solve the problem

Solution of 405 not allowed error in nginx

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

1. The first page you see is the page returned by nginx. You know that the error should be solved from nginx

Return to page:

<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.0.11</center>
</body>
</html>

2. Check the information online, because the static file requested here uses the post method, nginx does not allow post to access the static resources. In addition to the topic, I try to post an interview www.baidu.com Found that the page is also an error

3. Three solutions are posted

1. Pointing 405 error to success

Add error to location in static server_ page 405 =200 $uri;

location ~ ^/better/.*\.(htm|html|gif|jpg|jpeg|png|ico|rar|css|js|zip|txt|flv|swf|doc|ppt|xls|pdf|json|ico|htc)$ {
<span style="white-space:pre">	</span>root D:/code/BetterjrWeb;
<span style="white-space:pre">	</span>error_page 405 =200 $uri;
}

2. Modify the Src/HTTP/modules/NGX HTTP static module. C event under nginx

if (r->method & NGX_HTTP_POST) {
     return NGX_HTTP_NOT_ALLOWED;
}

Note out this paragraph, recompile, do not make install, copy the nginx file generated by compilation to SBIN, restart nginx

3. Modify the wrong interface direction (this way is widely spread on the Internet, but the request method is not changed, so it is not feasible, so the following method is adopted)

upstream static_backend {
    server localhost:80;
}

server {
    listen 80;
    # ...
    error_page 405 =200 @405;
    location @405 {
        root /srv/http;
        proxy_method GET;
        proxy_pass http://static_backend;
    }
}

CentOS starts nginx and prompts nginx: [emergency] still could not bind ()

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

[root@iZbp1aed32ln6eZ sbin]# netstat -ntlp|grep 80
tcp        0      0 127.0.0.1:8005          0.0.0.0:*               LISTEN      1501/java           
tcp        0      0 0.0.0.0:8009            0.0.0.0:*               LISTEN      1501/java           
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7225/nginx: master  
tcp        0      0 0.0.0.0:8081            0.0.0.0:*               LISTEN      7036/java           
[root@iZbp1aed32ln6eZ sbin]# kill -9 7225
[root@iZbp1aed32ln6eZ sbin]# ./nginx -s reload
nginx: [alert] kill(7225, 1) failed (3: No such process)
[root@iZbp1aed32ln6eZ sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@iZbp1aed32ln6eZ sbin]# netstat -ntlp|grep 80
tcp        0      0 127.0.0.1:8005          0.0.0.0:*               LISTEN      1501/java           
tcp        0      0 0.0.0.0:8009            0.0.0.0:*               LISTEN      1501/java           
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7276/nginx: worker  
tcp        0      0 0.0.0.0:8081            0.0.0.0:*               LISTEN      7036/java           
[root@iZbp1aed32ln6eZ sbin]# killall -9 nginx
[root@iZbp1aed32ln6eZ sbin]# systemctl restart nginx
Failed to restart nginx.service: Unit not found.
[root@iZbp1aed32ln6eZ sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@iZbp1aed32ln6eZ sbin]# ./nginx -s reload

The solution of nginx executing PHP, no input file specified

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

After configuring nginx, an error will appear when executing PHP file, and “no input file specified” will be displayed

Methods introduced online, such as modifying fastcgi_ The value of param instruction is absolute path, modifying php.ini file and so on are not the most fundamental solutions, and the key cause of the problem is not found

the root cause of “no input file specified” is the incorrect configuration of nginx, which leads to the error of CGI getting parameters . Simply put, it’s $document_ Root is not defined. In the configuration file

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

Is the instruction statement written in the location block (usually matching PHP)

We know that there are three levels of relationship in the configuration file of nginx, HTTP > server > location。 If you want to use $document in location_ Root, you need to define the root instruction in the upper server block or HTTP block, so that you can use $document in the location through the inheritance relationship_ Root gets the value of root. The root instruction value defined in another location is a local variable, and its value cannot be obtained in the location matching PHP

Therefore, the solution to this problem is to move the root in the “/” location up to in the server block. Or, redefines root in the location block of PHP

Nginx report 500 internal server error

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

Today, a nginx is deployed. Web page access always reports 500 errors (500 internal server error). After entering the error.log of nginx, it is found that it has been reporting too many open files

2018/08/21 10:07:35 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:35 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:36 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:36 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:37 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:37 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:38 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:38 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:39 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:39 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:40 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:40 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:41 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:41 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:42 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:42 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:43 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:43 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:44 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:44 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:45 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:45 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:46 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:46 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:47 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:47 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:48 [crit] 13508#13508: accept4() failed (24: Too many open files)

I guess the file open is beyond the upper limit set by the system, so I log in to the server to check

Run the following command to view

[root@server nginx]$ ulimit -n  
1024
[root@server nginx]$ 

It’s only 1024. Since it’s so small, let’s revise it

But before we modify it, let’s confirm the upper limit of the system

[root@server nginx]# sysctl -n -e fs.file-max
13057331
[root@server nginx]# 

Since there are so many, I don’t worry. I don’t want many

Start to modify the maximum number of open files, in the/etc/security/limits. Conf file, and add

* soft nofile 10240
* hard nofile 10240

# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the system services.
#
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4

* soft nofile 10240
* hard nofile 10240
# End of file

Then log out, go in and check it, and find that it has been set

[root@server nginx]$ ulimit -n  
10240
[root@server nginx]$ 

Then restart nginx, it should be OK