CentOS 7 yum 安装 Nginx

来源:互联网 发布:长沙淘宝仓库打包招聘 编辑:程序博客网 时间:2024/05/24 02:39
 

CentOS 7 yum 安装 Nginx


1.添加Nginx到YUM源

添加CentOS 7 Nginx yum资源库,打开终端,使用以下命令:

sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.安装Nginx

在你的CentOS 7 服务器中使用yum命令从Nginx源服务器中获取来安装Nginx:

sudo yum install -y nginx

Nginx将完成安装在你的CentOS 7 服务器中。

3.启动Nginx

刚安装的Nginx不会自行启动。运行Nginx:

sudo systemctl start nginx.service

如果一切进展顺利的话,现在你可以通过你的域名或IP来访问你的Web页面来预览一下Nginx的默认页面;

nginx_default

如果看到这个页面,那么说明你的CentOS 7 中 web服务器已经正确安装。

CentOS 7 开机启动Nginx

sudo systemctl enable nginx.service

更多systemctl命令可查看《systemctl命令用法》

Nginx配置信息

网站文件存放默认目录

/usr/share/nginx/html

网站默认站点配置

/etc/nginx/conf.d/default.conf

自定义Nginx站点配置文件存放目录

/etc/nginx/conf.d/

Nginx全局配置

/etc/nginx/nginx.conf

Nginx启动

nginx -c nginx.conf

在这里你可以改变设置用户运行Nginx守护程序进程一样,和工作进程的数量得到了Nginx正在运行,等等。
service nginx start


现在Nginx已经启动了,直接访问服务器就能看到Nginx欢迎页面了的。


如果还无法访问,则需配置一下Linux防火墙。


iptables -I INPUT 5 -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT


service iptables save


service iptables restart


Nginx的命令以及配置文件位置:


service nginx start # 启动Nginx服务
service nginx stop # 停止Nginx服务
service nginx.conf # Nginx配置文件位置
 vi /etc/nginx/nginx.conf 更改root 配置 为新的web目录

This is the default index.html page that is distributed withnginx on Fedora. It is located in/usr/share/nginx/html.

You should now put your content in a location of your choice and edit theroot configuration directive in thenginx configuration file/etc/nginx/nginx.conf.



Linux查看公网IP

您可以运行以下命令来显示你的服务器的公共IP地址:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
原创粉丝点击