❶ 如何在linux系统下安装nginx
step1. 在 /home 下创建 nginx 文件夹 将 nginx-1.7.8.tar.gz 上传到 nginx 文件夹下
step2. 解压 tar -xzvf nginx-1.7.8.tar.gz
step3. 进入 nginx-1.7.8 中
step4. 执行 ./configure --prefix=/usr/local/nginx-1.7.8 --with-http_ssl_mole --with-http_spdy_mole --with-http_stub_status_mole --with-pcre
step5. 执行 make && make install
step6. 查看配置 /usr/local/nginx-1.7.8/sbin/nginx -t
如果显示以下两行信息 说明配置正确:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
step7. 启动 /usr/local/nginx-1.7.8/sbin/nginx
step8. 如遇上图报错 则使用命令关闭占用 80 端口的程序 sudo fuser -k 80/tcp
step9. 再次启动成功
step10. 浏览器检验 出现下图界面表示安装启动成功
❷ 如何在linux下搭建nginx服务器
1、下载后解压nginx
tar -zxvf nginx-1.4.7.tar.gz
2、安装gcc等依赖包
yum -y install gcc pcre-devel openssl openssl-devel
3、开始安装nginx
cd进入nginx-1.4.7目录内
./configure 编译
make&&make install 这一步需要先cd出来吗?在里面会安装失败吗?我忘了 = =
4、此时就已经安装完成,默认安装在了/usr/local/nginx/sbin/nginx
5、启动
命令行输入/usr/local/nginx/sbin/nginx,没反应
输入ps -ef | grep nginx查看nginx进程
6、测试
命令行输入 curl http://127.0.0.1
会出现welcome to nginx之类的就说明对了!
7、加入到环境变量
vim /etc/profile
尾行添加
PATH=$PATH:/usr/local/nginx/sbin
export PATH
保存关闭后运行 source /etc/profile 即会加入环境变量
8、常用命令
[root@ usr]# nginx -s stop停止nginx
[root@ usr]# nginx 运行nginx
[root@ usr]# nginx -s reload 重启nginx
[root@ usr]# nginx -t 测试nginx
9、防火墙允许外网访问
vim /etc/sysconfig/iptables
添加过滤规则
-A -INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
好像是保存后即时生效把?
service iptables stop
service iptables start
重启服务后还是会生效,亲测
10、修改网站默认根目录路径
网站默认根目录放在/usr/local/nginx/html
命令行输入 vim /usr/local/nginx/conf/nginx.conf
找到改为
server {
listen 80;
server_name localhost;
root /var/www/html/default;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root html;
index index.html index.htm;
}
注释掉下面的,在上面添加自己想要的根目录,重启nginx才能生效。
❸ linux 中 nginx怎么样安装
①- 配置yum源
cd /etc/yum.repos.d/
vim nginx.repo
###添加下面内容到nginx.repo文件
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1
②- yum -y install nginx
③- chkconfig nginx on
###设置centos redhat 6版本 及其以下版本 开机自启动
④- systemctl enable nginx
###设置centos redhat 7版本 开机自启动