设为首页 收藏本站
查看: 493|回复: 0

[经验分享] How To Install Nginx on CentOS 7(转)

[复制链接]

尚未签到

发表于 2017-11-15 14:46:46 | 显示全部楼层 |阅读模式
How To Install Nginx on CentOS 7

PostedJuly 22, 2014 427.4kviews NGINX CENTOS


About Nginx
  Nginx is a high performance web server software. It is a much more flexible and lightweight program than Apache HTTP Server.
  This tutorial will teach you how to install and start Nginx on your CentOS 7 server.



Prerequisites
  The steps in this tutorial require the user to have root privileges. You can see how to set that up by following steps 3 and 4 in the Initial Server Setup with CentOS 7 tutorial.



Step One—Add Nginx Repository
  To add the CentOS 7 EPEL repository, open terminal and use the following command:

sudo yum install epel-release



Step Two—Install Nginx
  Now that the Nginx repository is installed on your server, install Nginx using the following yum command:

sudo yum install nginx

  After you answer yes to the prompt, Nginx will finish installing on your virtual private server (VPS).



Step Three—Start Nginx
  Nginx does not start on its own. To get Nginx running, type:

sudo systemctl start nginx

  If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:

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

  You can do a spot check right away to verify that everything went as planned by visiting your server's public IP address in your web browser (see the note under the next heading to find out what your public IP address is if you do not have this information already):

http://server_domain_name_or_IP/

  You will see the default CentOS 7 Nginx web page, which is there for informational and testing purposes. It should look something like this:

  If you see this page, then your web server is now correctly installed.
  Before continuing, you will probably want to enable Nginx to start when your system boots. To do so, enter the following command:

sudo systemctl enable nginx

  Congratulations! Nginx is now installed and running!

How To Find Your Server's Public IP Address
  To find your server's public IP address, find the network interfaces on your machine by typing:

ip addr

1. lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
. . .
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
. . .

  You may see a number of interfaces here depending on the hardware available on your server. The lointerface is the local loopback interface, which is not the one we want. In our example above, the eth0interface is what we want.
  Once you have the interface name, you can run the following command to reveal your server’s public IP address. Substitute the interface name you found above:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'



Server Root and Configuration
  If you want to start serving your own pages or application through Nginx, you will want to know the locations of the Nginx configuration files and default server root directory.

Default Server Root
  The default server root directory is /usr/share/nginx/html. Files that are placed in there will be served on your web server. This location is specified in the default server block configuration file that ships with Nginx, which is located at /etc/nginx/conf.d/default.conf.

Server Block Configuration
  Any additional server blocks, known as Virtual Hosts in Apache, can be added by creating new configuration files in /etc/nginx/conf.d. Files that end with .conf in that directory will be loaded when Nginx is started.

Nginx Global Configuration
  The main Nginx configuration file is located at /etc/nginx/nginx.conf. This is where you can change settings like the user that runs the Nginx daemon processes, and the number of worker processes that get spawned when Nginx is running, among other things.



See More
  Once you have Nginx installed on your cloud server, you can go on to install a LEMP Stack.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-407256-1-1.html 上篇帖子: Centos 7 修改时区 下篇帖子: vmware虚拟机安装CentOS-6.5教程
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表