您的位置 首页 php

如何在CentOS和RHEL和Fedora上安装NGINX Web服务器

nginx(engine x)是一个功能强大的web服务器,由于其速度快,所以非常受欢迎。nginx还用作反向代理服务器。本篇文章将介绍在CentOS、Rhel和Fedora系统上设置nginx。

步骤1:安装nginx

nginx包在默认存储库中可用。执行以下命令以在系统上安装最新的nginx可用版本。

$ yum install nginx    $ dnf install nginx#On Fedora 22+ systems

步骤2:nginx基本配置

在启动nginx之前进行一些初始设置。编辑nginx主配置文件/etc/nginx/nginx.conf并更新值。

$ vim /etc/nginx/nginx.conf

更新以下值:

worker_processes  4;   # Number of CPU available in system listen  80;  # Port on which nginx will listen

步骤3:启动nginx服务

使用以下命令启动nginx Web服务器,并在系统启动时将nginx配置为自动启动。

$ systemctl enable nginx.service$ systemctl start nginx.service

现在,使用你最喜欢的浏览器访问端口80上的服务器,它将显示默认的nginx页面。

步骤4:在nginx中创建virtualhost

在对nginx进行初始配置更改后,我们从配置第一个虚拟主机开始。首先为应用程序创建文档根目录。

$ sudo mkdir -p /var/www/example.com/httpdocs$ sudo chown -R nginx.nginx /var/www/example.com

现在创建一个带有示例文本的索引文件

$ echo "Welcome to NGINX" > /var/www/example.com/httpdocs/index.html

现在创建一个虚拟主机配置文件。只是创建一个名为example.com.conf的default.conf文件的副本,并在编辑器中编辑该文件。

$ cp /etc/nginx/conf.d/virtual.conf /etc/nginx/conf.d/example.com.conf$ vim /etc/nginx/conf.d/example.com.conf

像下面这样对配置文件进行一些更改,并保持其他设置不变。

server {    listen       80;    server_name  example.com;    location / {        root   /var/www/example.com/httpdocs;        index  index.html index.htm;    }

最后,使用以下命令重新启动nginx服务

$ sudo systemctl restart nginx.service

本篇文章到这里就已经全部结束了,更多其他精彩内容大家可以关注PHP中文网的PHP视频教程栏目!

以上就是如何在CentOS和RHEL和Fedora上安装NGINX Web服务器的详细内容,更多请关注求知技术网其它相关文章!

文章来源:智云一二三科技

文章标题:如何在CentOS和RHEL和Fedora上安装NGINX Web服务器

文章地址:https://www.zhihuclub.com/6022.shtml

关于作者: 智云科技

热门文章

网站地图