How To Install Nginx on CentOS 7

PostedJuly 22, 2014 427.4kviews NGINX CENTOS

About Nginx

Nginx is a high performance web server software. It is a much more flexible and lightweight program than Apache HTTP Server.

This tutorial will teach you how to install and start Nginx on your CentOS 7 server.

 

Prerequisites

The steps in this tutorial require the user to have root privileges. You can see how to set that up by following steps 3 and 4 in the Initial Server Setup with CentOS 7 tutorial.

 

Step One—Add Nginx Repository

To add the CentOS 7 EPEL repository, open terminal and use the following command:

sudo yum install epel-release
 

Step Two—Install Nginx

Now that the Nginx repository is installed on your server, install Nginx using the following yum command:

sudo yum install nginx

After you answer yes to the prompt, Nginx will finish installing on your virtual private server (VPS).

 

Step Three—Start Nginx

Nginx does not start on its own. To get Nginx running, type:

sudo systemctl start nginx

If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

You can do a spot check right away to verify that everything went as planned by visiting your server's public IP address in your web browser (see the note under the next heading to find out what your public IP address is if you do not have this information already):

http://server_domain_name_or_IP/

You will see the default CentOS 7 Nginx web page, which is there for informational and testing purposes. It should look something like this:

If you see this page, then your web server is now correctly installed.

Before continuing, you will probably want to enable Nginx to start when your system boots. To do so, enter the following command:

sudo systemctl enable nginx

Congratulations! Nginx is now installed and running!

How To Find Your Server's Public IP Address

To find your server's public IP address, find the network interfaces on your machine by typing:

ip addr
1. lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN

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

You may see a number of interfaces here depending on the hardware available on your server. The lointerface is the local loopback interface, which is not the one we want. In our example above, the eth0interface is what we want.

Once you have the interface name, you can run the following command to reveal your server’s public IP address. Substitute the interface name you found above:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
 

Server Root and Configuration

If you want to start serving your own pages or application through Nginx, you will want to know the locations of the Nginx configuration files and default server root directory.

Default Server Root

The default server root directory is /usr/share/nginx/html. Files that are placed in there will be served on your web server. This location is specified in the default server block configuration file that ships with Nginx, which is located at /etc/nginx/conf.d/default.conf.

Server Block Configuration

Any additional server blocks, known as Virtual Hosts in Apache, can be added by creating new configuration files in /etc/nginx/conf.d. Files that end with .conf in that directory will be loaded when Nginx is started.

Nginx Global Configuration

The main Nginx configuration file is located at /etc/nginx/nginx.conf. This is where you can change settings like the user that runs the Nginx daemon processes, and the number of worker processes that get spawned when Nginx is running, among other things.

 

See More

Once you have Nginx installed on your cloud server, you can go on to install a LEMP Stack.

 

How To Install Nginx on CentOS 7(转)的更多相关文章

  1. Install Nginx on CentOS 7

    To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with ...

  2. Install nginx on centos

    1. 安装wget. sudo yum -y install wget 2. 下载nginx发布代码. sudo wget http://nginx.org/download/nginx-1.8.0. ...

  3. [转载]How To Install Nginx And PHP-FPM On CentOS 6 Via Yum

    http://www.lifelinux.com/how-to-install-nginx-and-php-fpm-on-centos-6-via-yum/ http://blog.csdn.net/ ...

  4. Install NGINX, PHP-FPM (5.6) on CentOS 6

    Installing NGINX with PHP on CentOS 6 can be a hassle depending on the install and packages you use. ...

  5. Centos 7下安装nginx,使用yum install nginx,提示没有可用的软件包

    Centos 7下安装nginx,使用yum install nginx,提示没有可用的软件包. 18 (flaskApi) [root@67 flaskDemo]# yum -y install n ...

  6. yum install nginx

    先安装nginx的yum源 http://nginx.org/en/linux_packages.html#stable 找到链接,安装: rpm -ivh http://nginx.org/pack ...

  7. Docker 实战(二)——centos7镜像安装nginx,将安装nginx的centos容器生成新的镜像,并导出

    Docker centos7镜像安装nginx 1.安装docker 使用yum安装docker不再重复:见  Linux常用命令 2.pull centos 1)在docker仓库中搜索centos ...

  8. ASP.NET Core Docker jexus nginx部署-CentOS实践版

    本文用图文的方式记录了我自己搭建centos+asp.net core + docker + jexus + nginx的整个过程,希望对有同样需求的朋友有一定的参考作用. 本文主要内容如下: cen ...

  9. nginx在centos & ubuntu上的安装

    安装Centos 添加当前账号加入sudoers,具备sudo功能 安装编辑器vim Yum install vim Su root Cd cp /etc/sudoers /etc/sudoers[d ...

随机推荐

  1. 代码内存泄露检测工具(linux gcc + valrind)

    参考博客: https://www.cnblogs.com/wangkangluo1/archive/2011/07/20/2111248.html linux命令如下:valgrind --tool ...

  2. csps模拟测试7576一句话题解

    题面:https://www.cnblogs.com/Juve/articles/11694454.html 75考了数学,化学和物理... T1: 假设有一个A和B,那么对于每一个j!=i,都有$\ ...

  3. LUOGU P1654 OSU! (概率期望)

    传送门 解题思路 首先考虑对于一个点来说,如果这个点是1的话,那么对于答案来说 $(ans+1)^3=ans^3+3*ans^2+3*ans+1$,这对于上一个答案来说其实贡献了 $3*ans^2+3 ...

  4. maven相互依赖导致无法编译成功

    起初是新加了个模块,启动前编译时error,提示找不到依赖模块的类,但java文件上是没有报错的. 后经过排查,发现是循环依赖导致的此问题. 如图,弹出框中有循环依赖的模块会显示红色,右键Open M ...

  5. 大O法时间复杂度计算

    困惑的点——log,如何计算得出? ① 上限:用来表示该算法可能有的最高增长率. ② 大O表示法:如果某种算法的增长率上限(最差情况下)是f(n),那么说这种算法“在O(f(n))中”.n为输入规模. ...

  6. 基于用户的最近邻协同过滤算法(MovieLens数据集)

      基于用户的最近邻算法(User-Based Neighbor Algorithms),是一种非概率性的协同过滤算法,也是推荐系统中最最古老,最著名的算法. 我们称那些兴趣相似的用户为邻居,如果用户 ...

  7. Spring boot获取yml字段内容为null的各种情况

    首先,在resource目录下配置test.yml文件 A: B: http://123.com? C: username="lili"&password="12 ...

  8. MySQL5.6 community从下载到安装

    一, 官网下载: https://www.mysql.com/downloads/      二, 安装过程 1, 双击打开 安装 这里是进行数据库配置: 端口默认为3306 这里我们更改为1207 ...

  9. AlexNet详细解读

    AlexNet详细解读 目前在自学计算机视觉与深度学习方向的论文,今天给大家带来的是很经典的一篇文章 :<ImageNet Classification with Deep Convolutio ...

  10. let和const的一些知识点

    let和const 不可以重复声明 不会发生变量提升,因此必须在声明之后使用,否则报错! 只在声明所在的块级作用域内有效 let 同一个作用域内不能重复声明同一个变量: function func() ...