CentOS安装Nginx及默认配置指南

Kevin 杂记 955 次浏览 24条评论

平时有些调试操作需要在Web环境下进行,除了本地电脑用XAMPP之类软件解决外,也可以直接在服务器上安装Nginx使用。下面介绍如何在CentOS系统下快速配置Nginx服务,安装方法参考自官方文档,并就实际可能遇到的问题做了一些补充。其它Linux发行版系统安装步骤,请查看这个链接

Nginx 安装

1. Nginx直接用yum安装会提示找不到软件包,需要先添加官方软件源。

vi /etc/yum.repos.d/nginx.repo创建配置文件,复制下面内容添加到文件保存。这里设置的是适用于CentOS 7的Nginx稳定版,CentOS 6则相应改下里面的版本号。

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

若要安装最新版,baseurl参数改为http://nginx.org/packages/mainline/centos/7/$basearch/

2. 更新yum索引,然后安装Nginx。

yum update
yum install -y nginx

3. 设置防火墙允许HTTP访问,也就是放行80端口。

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

4. 启动Nginx服务,并设置开机自启。

systemctl start nginx
systemctl enable nginx

Nginx 配置

完成上面步骤后,访问服务器IP看到默认页面就可以开始使用了。如果要放多个网站需要另外创建虚拟机,这个部分以后再介绍。

Welcome to nginx!

默认网站目录在/usr/share/nginx/html,默认配置文件则是/etc/nginx/conf.d/default.conf

补充:若编译安装的Nginx,默认目录通常为/usr/local/nginx/html

修改配置文件后需要systemctl restart nginx重启服务生效。

评论列表

  1. #1

    acyclovir cost without insurance https://www.herpessymptomsinmen.org/productacyclovir/

  2. #2

    dapoxetine and cocaine mix https://salemeds24.wixsite.com/dapoxetine

  3. #3

    ivermectin drug https://ivermectin.webbfenix.com/

  4. #4

    vidalista and heart medication https://vidalista.mlsmalta.com/

  5. #5

    clomid effectiveness on full stomach https://salemeds24.wixsite.com/clomid

  6. #6

    hydroxychloroquine without prescription https://hydroxychloroquine.mlsmalta.com/

  7. #7

    purchasing bimatoprost on the internet https://carepro1st.com/

  8. #8

    cialis 20mg cost walmart http://www.lm360.us/

  9. #9

    hydroxychloroquine over the counter https://hydroxychloroquine.webbfenix.com/

  10. #10

    ivermectin for scabies adults https://ivermectin.mlsmalta.com/

  11. #11

    difference sildenafil and sildenafil citrate http://droga5.net/

  12. #12

    dapoxetine testimonials reviews https://dapoxetine.bee-rich.com/

  13. #13

    how many vidalista per prescription https://vidalista40mg.mlsmalta.com/

  14. #14

    free proair inhaler amazon https://amstyles.com/

  15. #15

    benefits of cialis for men https://wisig.org/

  16. #16

    women priligy https://ddapoxetine.com/

  17. #17

    publix pharmacy refills online https://buymeds.mlsmalta.com/

  18. #18

    publix pharmacy refills online https://edmeds.buszcentrum.com/

  19. #19

    chloroquine phosphate mechanism of action https://hydroxychloroquinee.com/

  20. #20

    atrial fibrillation and taking cialis https://tadalafil24.online/

  21. #21

    is hydroxychloroquine a prophylactic https://hydroxychloroquine.lm360.us/

  22. #22

    is hydroxychloroquine a prophylactic https://hydroxychloroquine.mymvrc.org/

  23. #23

    cenforce side effects blood pressure http://cavalrymenforromney.com/

  24. #24

    100 viagra pills for 99.00 https://viaplz.com/

发表评论

电邮地址用于 Gravatar 头像显示,不会被公开可见。