Tag Archives: nginx

/var/run/nginx/nginx.pid” failed (2: No such file or directory)

The nginx server keeps reporting the following error when the server is shut down and restarted:

[root@localhost sbin]# nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)

Solution:

    /> /local/nginx/conf/

     cd /usr/local/nginx/conf/
    
      Edit the configuration file nginx.conf
    vi nginx.conf
    
      The following code is commented in the configuration file:
    #pid   logs/nginx.pid;
    
      removes the comment, i.e. #, and changes it to the following code:
    pid    /usr/local/nginx/logs/nginx.pid;
    
      Press ESC, enter the following code, save and exit
    :wq
    
      > create logs directory in /usr/local/nginx:
    [root@localhost conf]# mkdir /usr/local/nginx/logs
    
      Start the nginx service:
    /usr/local/nginx/sbin/nginx
    

    Pro test successful!

Nginx can’t successfully reload

Nginx could not reload smoothly
A problem with Nginx being unable to dynamically hot reload was encountered
The daemon and master processes were shut down for debugging purposes before being discovered

daemon off;
master_process off; 

This causes the reload management to fail

#daemon off;
#master_process off; 

Comment out and it’s OK.

The solution of centos7 in VMware virtual machine unable to access after installing nginx

VMware virtual machine in Centos7 after installing NGINX is not native access solution
To install Nginx on Linux, see: Linux Centos7 to install Nginx
The firewall of CentOS is changed to “iptables”, which is no longer called “iptables”. The firewall of CentOS is changed to “iptables”, which is no longer called “iptables”. The firewall of CentOS is changed to “iptables”.

firewall-cmd --zone=public --add-port=80/tcp --permanent  

Command meaning:
— zone # scope
— add-port=80/ TCP # Add port in format: port/communication protocol
— permanent # is permanent and will fail if restarted without this parameter
Restart firewall:

systemctl stop firewalld.service  
systemctl start firewalld.service  

Refresh the access again, as shown in the figure below:

The garbled problem of hot deployment in nginx

Nginx-style IK hot deployment and its messy code problems
1. Create dic file

2 under the sibling directory of nginx. Adds a remote participle to the ik participle configuration file
After
is configured, restart nginx and elastic search.
Linux system configuration is the same as window configuration
if there is a problem with messy code, please see the following messy code solution
Messy code problem solved, pro – test available
1. Add nginx to Server
default_type 'text/html'; charset utf-8;
Add the following code to Elastic

-Xms1g
-Xmx1g
-Dfile.encoding=GBK

Error! Failed to start nginx

The following error occurred when the blogger started the Nginx service

[root@localhost ~]# /usr/local/nginx/sbin/nginx 
nginx: [emerg] getpwnam("nginx") failed

The function of getPwnam in the error message is to get information about the user’s login
So you can see that getting “nginx” users failed
Query the user with id, and sure enough, it does not exist

[root@localhost ~]# id nginx
id: nginx: no such user

Once the user is added, it works

[root@localhost ~]# useradd -M -s /sbin/nologin nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx
[root@localhost ~]# netstat -anpt | grep nginx
tcp        0      0 10.0.0.100:80           0.0.0.0:*               LISTEN      3843/nginx: master  

Recall that the configuration for source code compilation and installation was as follows

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make && make install 

At that time, the user group and user group of Nginx were set. In the absence of nginx users in the system, it could not be started naturally.

[/ usr / share / Doc / pcre-8.32/makefile] error 127 solution

The installation of Nginx prompts the need for pcRE library, which needs to be specified by the parameter — with-PCRE. Check that the system has installed PCRE through the RMP-QL command, as shown in the figure below:

When configuring the nginx option with configurer, specifying the pcRE directory as /usr/share/doc/pcre-8.32 will not make an error, as shown in the question. The reason for this error is that — with-PCRE requires you to specify the source directory of the PCRE, not the installation directory, download the PCRE, unzip it, and then configurer specifies it to the unzip it, and when you run make again, it passes.
Zlib depends on libraries in the same way. Zlib is installed in the system, but the zlib specified by configurer cannot be /usr/share/doc/zlib-1.2.7.

You need to download Zlib and unzip it, specifying –with-zlib=/path/to/zlib-source at configurer

Record a front end error net:: err_ HTTP2_ PROTOCOL_ ERROR 200

A browser visiting a front-end resource sends an error net::ERR_HTTP2_PROTOCOL_ERROR 200, or an Intranet request sends an error net::ERR_SPDY_PROTOCOL_ERROR 200, and accesses the resource path directly to receive the resource, but the original page is unavailable.
According to some data, it is said to restart ngxin. It is said that the location of Nginx is configured with proxy_max_temp_file_size 0. The second scheme takes effect after two schemes are tried once.

Ngixn exception net:: err_ HTTP2_ PROTOCOL_ ERROR 200

First, let’s look at the page error reporting example:

Net ::ERR_HTTP2_PROTOCOL_ERROR 200 shows up after multiple calls from multiple interfaces
Therefore, it is basically concluded that it is not a single interface or database problem, because we used four Nginx for load balancing and forwarding, so it is basically concluded that nginx is the problem, but which machine in Nginx and what causes it?
The positioning strategy in 2 is given below:
1) Observe the HEADER information in HTTP every time there is an error, and count the nginx information corresponding to via label in the header every time. This method can be derived from the problem of Nginx.
Below:
 
2) In the dead of night, no one else called the service, so I called it by myself. I checked the log files of each Nginx service separately to see which machine would have error information when there was a problem. Here is my machine error log:
2020/07/13 11:45:52 [Error] 20217#0: *85294045 Open () “/usr/local/nginx-1.18/ HTML /50x.html” failed (2: No such File or Directory), Client: 100.97.200.204, Server: www.test.com, Request: “POST/API/core/scratch/exercise/HTTP/1.1”, the host: “www.test.com”, referrer, “https://www.test.com/scratch/v3/?token=aee00163e0b79bf004a0001& projectType=1& practiceType=2& lesson=0172cd54dad800163e0b79bf004a0001& class=7712bc6db96f48febccafe008d9869a1& templateId=65032& category=2& role=1& fr=ts& canSave=1& isOnline=0”
This method gives the specific reason for the error, which I have seen here is that the file does not exist and cannot be opened.
Then I communicated with operation and maintenance and found out that Nginx upgraded today, but only reload was not restarted, so the solution to the problem caused by some cached information was to restart Nginx after operation and maintenance.
Here’s an article on the difference between nginx restart and Reload:
https://www.cnblogs.com/fanggege/p/12145956.html
 

Ubuntu 20.04 builds nginx 1.18.0 and MAC file transfer / download to server

Install Nginx, configure firewall and file structure; SFTP transfer download, SCP upload download.
// it is not clear here that it is very similar to the last one.

Nginx
Install Nginx
Apt get update
apt install nginx;
after installation, the service will be automatically executed,
verification: systemctl status nginx;
Configure the firewall
ufw allow 'Nginx;
verification :ufw status;
Successful execution interface

File structure

all Nginx configuration files are located in /etc/nginx directory.
the main configuration file for Nginx is /etc/nginx/nginx.conf. To make the Nginx configuration easier to maintain, it is recommended to create a separate configuration file for each domain. You can have as many server block files as you want.
Nginx server prevents files from being stored in the /etc/nginx/ locations-available directory. Nginx will not use the configuration files found in this directory unless they are linked to the /etc/nginx/ location-enabled directory.
to activate the server block, you need to create a symbolic link (pointer) from the configuration file site in the sites-available directory to the directory sites-enabled.
is recommended to follow standard naming conventions. For example, if your domain name is mydomain.com, then your configuration file should be named /etc/nginx/sites-available/mydomain.com.conf
the/etc/nginx/snippets directory contains can included in the configuration file from the server. If you use repeatable configuration segments, you can refactor these segments into fragments and include the fragment file in the server block.
Nginx log files (access.log and error.log) are located in the /var/log/ Nginx directory. It is suggested that there are different Access, and the error is the log file of each server module.
The MAC sends files to the server
SFTP transfer download
Create a new remote connection in the shell and send it using SFTP (prompted for server password) :

Use put to send command: put local file path remote path ; The
put command cannot upload a folder directly. Can be packaged for delivery.
use the get download command get remote path ;
use bye to exit SFTP :bye.
SCP upload and download
1, from the server to download file SCP username @ servername:/path/filename/Users/MAC/Desktop (local directory)
For example: SCP [email protected]:/root/zouzouzou. TXT/Users/MAC/Desktop is the server/root/zouzouzou. TXT/Users/MAC/downloaded to a local Desktop directory.
[email protected]: SCP - r/raid5 ZXX/my_download/zouzouzou.zip/users/zhuxiaoxia/Desktop
2. Upload local files to the server SCP /path/filename username@servername:/path;
For example, SCP/Users/MAC/Desktop/zouzouzou. TXT [email protected]:/root/
3. Download the whole directory scp-r username@servername:/root/ (remote directory) /Users/ MAC /Desktop (local directory)
For example : scp-r [email protected]:/root/ /Users/ MAC /Desktop/
4. Upload directory to server scp-r local_dir username@servername:remote_dir
For example: scp-r test [email protected]:/root/ upload the test directory under current directory to the server's /root/ directory
Reminder: The target server wants to enable write permission.

Deployment project websocket failed: error during websocket Handshake: unexpected response code: 400

Fixed nginx forwarding WebSocket 400 error
Reprint link: https://www.cnblogs.com/duanweishi/p/9286461.html

because the personal server has a number of projects, configured with a secondary domain name, the need to forward the secondary domain name, in the forwarding work this quickly took the famous nginx. Before this, all the projects had no problem running forward, but today, when deploying a project with WebSocket communication, an unexpected error was reported, with the following error message:
Failed: Error during WebSocket handshake: Unexpected response code: 400
. This error worked in both the local test environment and access to non-Nginx forwarding, which inferred that the problem should have occurred in nginx forwarding.
Then, with the help of Google, saw the socket. IO official issues have a discussion about this problem, link: https://github.com/socketio/socket.io/issues/1942
Solution
read the solution in the discussion section, the problem appears in the configuration file of nginx, and the nginx.conf file needs to be modified. Type vim /etc/nginx/nginx.conf into the Linux terminal and find the location. The configuration file is as follows:

server {
        listen       80;
        server_name  school.godotdotdot.com;
        charset utf-8;

        location/{
            proxy_pass http://127.0.0.1:3000;
            proxy_set_header Host $host;
            proxy_http_version 1.1; 
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_connect_timeout 60;
           proxy_read_timeout 600;
           proxy_send_timeout 600;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 }

The most important of these are the following three lines

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

The first line tells Nginx to use the HTTP/1.1 communication protocol, which websoket must use.
The second and third lines tell Nginx to respond to an HTTP upgrade request when it wants to use WebSocket.
Supplement:

	server {
	        listen       80;
	        server_name  school.godotdotdot.com;
	        charset utf-8;
	        
			proxy_http_version 1.1; 
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";
	

	        location/{
	            proxy_pass http://127.0.0.1:3000;
	            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_connect_timeout 60;
	           proxy_read_timeout 600;
	           proxy_send_timeout 600;
	        }

	        error_page   500 502 503 504  /50x.html;
	        location = /50x.html {
	            root   html;
	        }
	 }