Skip to content

Instantly share code, notes, and snippets.

@ifels
Last active September 7, 2023 01:57
Show Gist options
  • Star 84 You must be signed in to star a gist
  • Fork 54 You must be signed in to fork a gist
  • Save ifels/c8cfdfe249e27ffa9ba1 to your computer and use it in GitHub Desktop.
Save ifels/c8cfdfe249e27ffa9ba1 to your computer and use it in GitHub Desktop.
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;
}
}
...
@geekyouth
Copy link

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

image

@tzh88
Copy link

tzh88 commented Mar 18, 2019

l love you

@Aermberry
Copy link

thx for save my time

@KeJX
Copy link

KeJX commented Aug 19, 2019

thx

@zhaohuanran
Copy link

好用!!谢谢了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment