Two ways to install nginx in centos7 (transfer)


The first way to install nginx on  centos7: installing nginx

    directly through yum is definitely not possible, because yum does not have nginx, so first add the source of nginx to yum.

Run the following commands:

1. Put nginx in the yum repro repository
[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. Use yum to install ngnix
[root@localhost ~]# yum install nginx The
effect is as follows:
[root@localhost ~] # yum install nginx
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.usc.edu
 * extras: mirror.raystedman.net
 * updates: mirror.metrocast.net
Resolving dependencies
--> checking affairs
---> Package nginx.x86_64.1.1.10.1-1.el7.ngx will be installed
      … Installing: 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/

-- -------------------------------------------------- ------------------
  Verifying: 1:nginx-1.10.1-1.el7.ngx.x86_64 1/ 1Installed

:
  nginx.x86_64 1:1.10.1 -1.el7.ngx                                                                                    
finished!

4. Start nginx
[root@localhost ~]# service nginx start

5. View nginx version
[root@localhost ~]# nginx -v

6. Access nginx, now you can view nginx through public network ip (locally through localhost / or 127.0.0.1 ) Information returned by the service.
[root@localhost ~]# curl -i localhost The
effect is as follows: Welcome to
      nginx
!. 7. The location of the nginx configuration file is /etc/nginx/ [root@localhost /]# ll /etc/nginx/ total usage 32
      drwxr -xr-x. 2 root root 25 October 12 13:11 conf.d -rw-r--r--. 1 root root 1007 May 31 22:09 fastcgi_params -rw-r--r--. 1 root root 2837 May 31 22:09 koi-utf -rw- r--r--. 1 root root 2223 May 31 22:09 koi-win -rw-r--r--. 1 root root 3957 May 31 22:09 mime.types








lrwxrwxrwx. 1 root root 29 Oct 12 13:11 modules -> ../../usr/lib64/nginx/modules
-rw-r--r--. 1 root root 643 May 31 22:08 nginx. conf
-rw-r--r--. 1 root root 636 May 31 22:09 scgi_params
-rw-r--r--. 1 root root 664 May 31 22:09 uwsgi_params
-rw-r--r --. 1 root root 3610 May 31 22:09 win-utf

8. Practice:
Purpose: Modify the service name, and then access this service from the outside
Operation:
a. Modify the nginx configuration file
[root@localhost nginx]# vim /etc /nginx/conf.d/default.conf
Modify the server_name part: server_name yytest.com;

b. Reload service
[root@localhost nginx]# /usr/sbin/nginx -s reload

c. Access nginx service from outside (192.168. 10.11)
For example, access from the browser of the client computer (192.168.10.10): http://yytest.com

d. You find that you cannot access it. Reason 1, you have not done mapping in the hosts file; Reason 2, you are in the hosts file in time There is no mapping, because the 80 port of the nginx server is blocked or the firewall is not closed

. The solution:
Step 1: Modify the hosts file of the client (192.168.10.10), use the SwitchHosts tool to add 192.168.10.11 yytest.com Step 2 :
Turn off the firewall, as described below Run service nginx start in any path (centos7 is systemctl start nginx.service ) to restart: $ /usr/sbin/nginx –s reload stop: $ /usr/sbin/nginx –s stop Test whether the configuration file is normal: $ /usr/  Possible problems with sbin/nginx –t :     The specific situation is as follows 1. This machine can ping virtual machine 2. The virtual machine can also ping the local machine 3. The virtual machine can access its own web 4. This machine cannot access the virtual web. The reason for this problem is that the server's port 80 is not open or the firewall is not closed . Solution If it is centos6: The solution is as follows: /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT Then save: /etc/rc.d/init.d/iptables save Restart the firewall /etc/init.d/iptables restart Close the CentOS firewall and close its services:































Check the CentOS firewall information: /etc/init.d/iptables status
Close the CentOS firewall service: /etc/init.d/iptables stop
Permanently close the firewall:
chkconfig –level 35 iptables off

If it is centos7
[root@rhel7 ~]# systemctl status firewalld.service

[root@rhel7 ~]# systemctl stop firewalld.service

[root@rhel7 ~]# systemctl disable firewalld.service

[root@rhel7 ~]# systemctl status firewalld.service

Extended knowledge:

start a service: systemctl start firewalld. service
Shut down a service: systemctl stop firewalld.service
Restart a service: systemctl restart firewalld.service
Display the status of a service: systemctl status firewalld.service
Enable a service at boot: systemctl enable firewalld.service
Disable a service at boot: systemctl disable firewalld.service

Check whether the service is started at boot: systemctl is-enabled firewalld.service;echo $?

Check the list of started services: systemctl list-unit-files|grep enabled

The second way: Manually download the installation package and decompress the installation

1. Download the nginx package .
[root@localhost ~]# wget http://nginx.org/download/nginx-1.10.1.tar.gz

2. Copy the package to your installation directory
[root@localhost ~]# cp nginx-1.10.1. tar.gz /usr/local/

3. Unzip
[root@localhost ~]# tar -zxvf nginx-1.10.1.tar.gz
[root@localhost ~]# cd nginx-1.10.1

4. Start nginx
[root@ localhost ~]# /usr/local/nginx/sbin/nginx

5. View version s
[root@localhost ~]# nginx -v

6.url access nginx localhost or 127.0.0.1

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326555153&siteId=291194637