Two ways to install centos7 nginx
- 2020-05-24 06:43:30
- OfStack
nginx centos7 installation
The first way: through yum installation
Going directly through yum install nginx is definitely not possible, since yum does not have nginx, so first add the nginx source to yum.
Run the following command:
1. Put nginx into the yum repro library
[root@localhost ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2. View nginx information
[root@localhost ~]# yum info nginx
3. Install ngnix using yum
[root@localhost ~]# yum install nginx
The effect is as follows:
[root@localhost ~]# yum install nginx
Loaded plug-ins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.usc.edu
* extras: mirror.raystedman.net
* updates: mirror.metrocast.net
Working on dependencies
--
>
Checking transaction
---
>
The package nginx.x86_64.1.1.10.1-1.el7.ngx will be installed
Are being installed: 1: nginx 1.10.1-1. el7. ngx. x86_64
Thanks for using nginx!
Please find the official documentation for nginx here:
* http://nginx.org/en/docs/
Commercial subscriptions for nginx are available on:
* http://nginx.com/products/
----------------------------------------------------------------------
Validation: 1: nginx 1.10.1-1. el7. ngx. x86_64 1/1
Installed:
nginx.x86_64 1:1.10.1-1.el7.ngx
Finished!
4. Start nginx
[root@localhost ~]# service nginx start
5. View the nginx version
[root@localhost ~]# nginx -v
6. Access nginx, you can now view the information returned by nginx service via the public network ip (locally via localhost/or 127.0.0.1).
[root@localhost ~]# curl -i localhost
The effect is as follows:
Welcome to nginx! .
7.nginx configuration file location is /etc/nginx/
[root@localhost /]# ll /etc/nginx/
The total amount 32
drwxr-xr-x. 2 root root 25 10 month 12 13:11 conf.d
-rw-r--r--. 1 root root 1007 5 month 31 22:09 fastcgi_params
-rw-r--r--. 1 root root 2837 5 month 31 22:09 koi-utf
-rw-r--r--. 1 root root 2223 5 month 31 22:09 koi-win
-rw-r--r--. 1 root root 3957 5 month 31 22:09 mime.types
lrwxrwxrwx. 1 root root 29 10 month 12 13:11 modules -> ../../usr/lib64/nginx/modules
-rw-r--r--. 1 root root 643 5 month 31 22:08 nginx.conf
-rw-r--r--. 1 root root 636 5 month 31 22:09 scgi_params
-rw-r--r--. 1 root root 664 5 month 31 22:09 uwsgi_params
-rw-r--r--. 1 root root 3610 5 month 31 22:09 win-utf
8. Practice:
Purpose: modify the name of the service and then access the service externally
Operation:
a. Modify the nginx configuration file
[root@localhost nginx]# vim /etc/nginx/conf.d/default.conf
Modify server_name part: server_name yytest.com;
b. Overloaded service
[root@localhost nginx]# /usr/sbin/nginx -s reload
c. External access to nginx services (192.168.10.11)
As in the client browser to access (192.168.10.10) : http: / / yytest com
d. You found that you could not access it, because 1, you did not map in the hosts file; 2. Reason 2, even if you have the mapping in the hosts file, port 80 of the nginx server is blocked or the firewall is not closed
e. Solution:
Step 1: modify the hosts file for the client (192.168.10.10) and use the SwitchHosts tool to add 192.168.10.11 yytest.com
Step 2: close the firewall, as described below
9.nginx common operations
Activation:
$ /usr/sbin/nginx Or run on any path service nginx start(centos7 is systemctl start nginx.service )
Resume:
$ /usr/sbin/nginx � s reload
Stop:
[root@localhost ~]# yum install nginx
0
Test whether the configuration file is normal:
[root@localhost ~]# yum install nginx
1
Possible problems:
The details are as follows: 1. This function ping through virtual machine 2. The virtual machine can also ping through the machine 3. The virtual capability accesses its own web 4. The reason for this problem is that port 80 of the server is not open or the firewall is not closed
The solution
If it is centos6:
The solution is as follows:
[root@localhost ~]# yum install nginx
2
Then save:
/etc/rc.d/init.d/iptables save
Restart the firewall
[root@localhost ~]# yum install nginx
4
Shut down the CentOS firewall and turn off its services:
See CentOS firewall information: / etc init d/iptables status
Closed CentOS firewall services: / etc init d/iptables stop
Permanently close the firewall: chkconfig, level 35, iptables off
If it is centos7
[root@localhost ~]# yum install nginx
5
Expand your knowledge:
Start 1 service: systemctl start firewalld.service
Close 1 service: systemctl stop firewalld.service
Restart 1 service: systemctl restart firewalld.service
Shows the status of a service: systemctl status firewalld.service
Enable 1 service on startup: systemctl enable firewalld.service
Disable 1 service at startup: systemctl disable firewalld.service
Check if the service is started on: systemctl is-enabled firewalld. service; echo $& # 63;
View the list of services that have been started: systemctl list-unit-files |grep enabled
The second way: manually download the installation package to unzip the installation
1. Download the nginx package.
[root@localhost ~]# yum install nginx
6
2. Copy the package to your installation directory
[root@localhost ~]# yum install nginx
7
3. Unzip
[root@localhost ~]# tar -zxvf nginx-1.10.1.tar.gz
[root@localhost ~]# cd nginx-1.10.1
4. Start nginx
[root@localhost ~]# yum install nginx
9
5. View version s
[root@localhost ~]# nginx -v
6.url access nginx localhost or 127.0.0.1