【nginx】Linux上安装nginx,开放端口并部署静态网页

8 篇文章 0 订阅
1 篇文章 0 订阅

安装环境

安装gcc,期间有提示,一律选y
[root@james nginx]#yum install gcc-c++
安装Nginx依赖环境,-y表示所有提示默认选择y
[root@james nginx]#yum -y install pcre pcre-devel  
[root@james nginx]#yum -y install zlib zlib-devel  
[root@james nginx]#yum -y install openssl openssl-devel

安装nginx运行环境

[root@james ~]# mkdir /usr/local/nginx
[root@james ~]# tar -zxvf nginx-1.13.9.tar.gz -C /usr/local/nginx
编译并安装
[root@james nginx]# cd nginx-1.13.9/
[root@james nginx]#./configure
 //  如果有error, 再执行一次 [root@james nginx]#yum -y install pcre pcre-devel  
[root@james ~]# make
[root@james ~]# make install

开放防火墙80端口

[root@james nginx]# vim /etc/sysconfig/iptables

插入
-I INPUT -p tcp --dport 80 -j ACCEPT
重新加载防火墙配置文件

[root@james nginx]# service iptables reload

观察index文件目录所在的根目录

[root@james nginx]# vim /usr/local/nginx/conf/nginx.conf
 server {
        listen       80;  // 监听80端口
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /ly;    // 项目跟路径, 修改成自己的项目路径(Linux)
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

部署静态网页的思路

  1. 上传自己的项目 PS ftp上传需要打成压缩包,再解压,记住解压的路径

  2. 修改nginx的配置,配置解压的路径

 location / {
            root   /ly;    // 项目跟路径, 修改成自己的项目路径(Linux)
            index  index.html index.htm;
        }

重启nginx

[root@james ~]# cd /usr/local/nginx/
[root@james nginx]# ls
client_body_temp  fastcgi_temp  logs          proxy_temp  scgi_temp
conf              html          nginx-1.13.9  sbin        uwsgi_temp
[root@james nginx]# cd sbin
停止Nginx
[root@james sbin]# ./nginx -s stop
启劝Nginx
[root@james sbin]# ./nginx

[ ../的区别转载至]:https://blog.csdn.net/u014471752/article/details/84565908
linux 中在shell中使用 " . " 和 " ./ " 执行的区别
目前注意到的区别主要在于环境变量的作用域上:

  1. 如果使用" ./ " 执行,可以理解为程序运行在一个全新的shell中,不继承当前shell的环境变量的值, 同时若在程序中改变了当前shell中的环境变量(不使用export),则当前shell的环境变量值不变。

  2. 如果使用” . "执行,则程序继承当前shell中的环境变量,同时,若在程序中改变了当前shell中的环境变量(不使用export),则当前shell中该环境变量的值也会改变

另外一个区别点在于, “ ./ "只能用于拥有执行权限的文件, 而 ” . " 则可以暂时提升

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值