CentOS安装Nginx及默认配置指南

Kevin 杂记 2,734 次浏览 44条评论

平时有些调试操作需要在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/

  25. #25

    safe to buy cialis online http://cialis.anafassia.com/

  26. #26

    installment loans

  27. #27

    levitra 20 mg canada

  28. #28

    get a loan without a job

  29. #29

    sildalis 100mg 20mg

  30. #30

    buy 20 mg tadacip

  31. #31

    guaranteed payday loan approval

  32. #32

    payday loans for bad credit

  33. #33

    loans with low interest

  34. #34

    brand cialis 20 mg

  35. #35

    payday money

  36. #36

    where can i buy levitra cheap

  37. #37

    payday loans for bad credit

  38. #38

    viagra for women uk

  39. #39

    ordering tadalafil https://cialis.bee-rich.com/

  40. #40

    ordering tadalafil https://cialis.mlsmalta.com/

  41. #41

    Please let me know if you’re looking for a writer for your blog. You have some really good articles and I think I would be a good asset. If you ever want to take some of the load off, I’d really like to write some content for your blog in exchange for a link back to mine. Please send me an email if interested. Many thanks!

    http://www.vreyrolinomit.com/

  42. #42

    buy hydroxychloroquine online https://hydroxychloroquinex.com/

  43. #43

    Hiya, I’m really glad I have found this information. Nowadays bloggers publish just about gossips and net and this is really irritating. A good blog with exciting content, this is what I need. Thanks for keeping this website, I’ll be visiting it. Do you do newsletters? Can not find it.

    https://alansolarshblog.wordpress.com/

  44. #44

    My coder is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using WordPress on various websites for about a year and am anxious about switching to another platform. I have heard excellent things about blogengine.net. Is there a way I can transfer all my wordpress content into it? Any kind of help would be greatly appreciated!

    https://www.youtube.com/watch?v=1fjWgYz9egs

发表评论

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