Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
centos 6.5 nginx安装与配置
第一步,在/etc/yum.repos.d/目录下创建一个源配置文件nginx.repo:
cd /etc/yum.repos.d/
vim nginx.repo
填写如下内容:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
保存,则会产生一个/etc/yum.repos.d/nginx.repo文件。
下面直接执行如下指令即可自动安装好Nginx:
yum install nginx -y
安装完成,下面直接就可以启动Nginx了:
/etc/init.d/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的命令以及配置文件位置:
/etc/init.d/nginx start # 启动Nginx服务
/etc/init.d/nginx stop # 停止Nginx服务
/etc/nginx/nginx.conf # Nginx配置文件位置
chkconfig nginx on #设为开机启动
至此,Nginx已经全部配置安装完成。
一台主机上适应多个服务器:
在你的nginx通过代理的方式转发请求:配置如下
vi /etc/nginx/nginx.conf
在http加入下面的内容,参考:http://wiki.nginx.org/FullExample
http {
....
server {
listen 80;
server_name www.a.com;
charset utf-8;
access_log /home/a.com.access.log main;
location / {
proxy_pass http://127.0.0.1:80;
}
}
server {
listen 80;
server_name www.b.com;
charset utf-8;
access_log /home/b.com.access.log main;
location / {
proxy_pass http://127.0.0.1:81;
}
}
...
@luckystar77

This comment has been minimized.

Copy link

commented Sep 23, 2017

嘿嘿,到时候试一下,我一直用windows,要试这个得装个虚拟机,搞个虚拟机装这环境的教程呗。

@harry-liu

This comment has been minimized.

Copy link

commented Nov 7, 2017

不错不错

@ifreesec

This comment has been minimized.

Copy link

commented Feb 28, 2018

点个赞

@fire2013

This comment has been minimized.

Copy link

commented Mar 16, 2018

确实不错

@enovelty

This comment has been minimized.

Copy link

commented Apr 1, 2018

多谢,centos 6.8 可用。
比网上其他教程强多了。

@hellogbx

This comment has been minimized.

Copy link

commented May 29, 2018

很赞

@geekyouth

This comment has been minimized.

Copy link

commented Oct 4, 2018

太赞了。不到两分钟就启动了nginx

image

@tanzhihui147

This comment has been minimized.

Copy link

commented Mar 18, 2019

l love you

@Salmonberry

This comment has been minimized.

Copy link

commented Mar 29, 2019

thx for save my time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.