2. Upload the downloaded nginx-1.16.1.tar.gz file to a specified file in Linux or Ubuntu
3. The nginx installation
tar -zxvf nginx-1.16.1.tar.gz / /
cd nginx-1.161.// Switch the directory
./configure --prefix=/usr/local/nginx // configures nginx to the /usr/local/ngnix directory
make / / compile
make install / / installationCopy the code
4. Common nginx commands
View the nginx installation location whereis nginx vim configuration file/usr/local/nginx/conf/nginx. Conf
See if any nginx process started ps – ef | grep nginx
Start the service/usr/local/nginx/sbin/nginx stop/restart/usr/local/nginx/sbin/nginx -s stop (quit, reload) to reload the configuration /usr/local/nginx/sbin/nginx -s reload
Start, stop, reload, restart, view the status service
Test whether or not the configuration file/usr/local/right nginx/sbin/nginx – t
5. Visit nginx
After nginx is enabled, access the server IP address locally, which is the server’s localhost. If you cannot access nginx, the firewall is not disabled. The Internet cannot be accessed after nginx is successfully configured
Setting up a firewall:
Ubuntu: $sudo ufw allow'Nginx Full'
$ sudo ufw status
Copy the code
Disable the firewall. [root@localhost ~]# service iptables stopDisable firewall startup after startup [root@localhost ~]# chkconfig iptables off
[root@localhost ~]# chkconfig --list|grep iptMethod 2 Add enabled ports to the firewall whitelist. Edit the firewall whitelist. [root@localhost ~]# vim /etc/sysconfig/iptables-a INPUT -p TCP -m state -- state NEW -m TCP --dport 80 -j ACCEPT save and exit, restart firewall [root@localhost ~]# service iptables restartCopy the code
Nginx load balancing configuration
Edit the configuration file: vim conf/nginx.conf
Each server is a virtual host that we can use as a Web server
server { listen 8001; Server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; // static file js, CSS, image, location / {root HTML; // Represents the root directory of the site index index.html index.htm; // represents default home page}}Copy the code
Upstream {} block. Nginx uses polling, IP hash, and weights as load balancing policies
upstream xxx{}; Upstream module is used to name a back-end server group. The group name must be the domain name of the back-end server site. IP addresses and ports of multiple servers can be written internally, and ip_hash can be set for jump rules and weights. Indicates that IP address assignment is used to redirect to the back-end server. The same IP address request accesses the same back-end server each time. Represents the address of the back-end server
server{}; The server module is still the part that receives external requests. Location / {}; Also represents filters, used to specify different operations for different requests proxy_pass; Indicates the name of the back-end server group. The group name must be the domain name of the back-end server site
The group names of server_name and upstream{} can be inconsistent. Server_name is the domain name used to receive requests from the Internet, while upstream{} is the domain name used to access the back-end server
Make [1]: Leaving directory ‘/usr/local/nginx-1.12.1; After the installation, leave the file;
Make [1]: Leaving directory ‘/usr/local/nginx-1.12.1; Leave it alone and continue to make install; /usr/local/nginx = /usr/local/nginx = /usr/local/nginx 2, If you already have nginx folder? Nginx can start normally. 4, If nginx starts successfully, let’s see if the website is accessible and if “Welcome to nginx!” ? 5, If the above all successful, your nginx has been ok!
Cc1: All warnings being treated as errors objs/Makefile:460: recipe for target ‘objs/src/core/ngx_murmurhash.o’ failed make[1]: [objs/src/core/ngx_murmurhash.o] Error 1 make[1]: Brigade directory ‘/ home/WZJ/tools/nginx/nginx – 1.11.3’ Makefile: 8: the recipe for target ‘build’ failed to make: [build] Error 2
Solution: Find the Maakefile file and remove -werror from GCC.
[root@localhost nginx]# systemctl status nginx.service ● nginx.service – LSB: starts the nginx Web server Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled) Active: failed (Result: exit-code) since Mon 2019-07-22 16:41:54 CST; 43s ago Docs: man:systemd-sysv-generator(8) Process: 28076 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=1/FAILURE)
Jul 22 16:41:54 localhost.localdomain systemd[1]: Starting LSB: starts the nginx web server…