您的位置:首页 > 运维架构 > Nginx

centos7 nginx安装

2016-04-12 08:03 483 查看
阿里云上买了个域名,准备玩一下。安装nginx

官网地址:

http://nginx.org/


官方文档,一步步来。

添加nginx源:

[root@xyjk1002 ~]# cat /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1


更新缓存

[root@xyjk1002 ~]# yum clean all & yum makecache


安装,好小

[root@xyjk1002 yum.repos.d]# yum install nginx
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.8.1-1.el7.ngx will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================
Package                                           Arch                                               Version                                                         Repository                                         Size
==============================================================================================================================================================================================================================
Installing:
nginx                                             x86_64                                             1:1.8.1-1.el7.ngx                                               nginx                                             372 k

Transaction Summary
==============================================================================================================================================================================================================================
Install  1 Package

Total download size: 372 k
Installed size: 897 k
Is this ok [y/d/N]:


开启服务:

[root@xyjk1002 ~]# systemctl start nginx.service


查看一下我们的公网ip

[root@xyjk1002 ~]# ip addr show eth1 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'


在浏览器中输入ip



出现页面,则说明成功

nginx默认配置文件:

[root@xyjk1002 ~]# cat /etc/nginx/conf.d/default.conf
server {
listen       80;
server_name  localhost;

#charset koi8-r;
#access_log  /var/log/nginx/log/host.access.log  main;

location / {
root   /usr/share/nginx/html;//网站根目录位置
index  index.html index.htm;//网站首页默认页面名称
}


最后添加防火墙规则:

[root@xyjk1002 ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@xyjk1002 ~]# firewall-cmd --reload
success
[root@xyjk1002 ~]# firewall-cmd --list-all
public (default)
interfaces:
sources:
services: dhcpv6-client ssh
ports: 80/tcp 22/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: