LINUX配置NGINX

首先,我下载的是nginx1.4.7

 

1、下载并解压nginx

    wget http://nginx.org/download/nginx-1.4.7.tar.gz

    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出来吗?在里面会安装失败吗?我忘了 = =

安装Nginx时报错

    ./configure: error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel解决问题
    yum -y install pcre-devel

 

错误提示:./configure: error: the HTTP cache module requires md5 functions
    from OpenSSL library.   You can either disable the module by using
    --without-http-cache option, or install the OpenSSL library into the system,
    or build the OpenSSL library statically from the source with nginx by using
    --with-http_ssl_module --with-openssl=<path> options.

解决办法:

    yum -y install openssl openssl-devel

 

总结:

     yum -y install pcre-devel openssl openssl-devel

    ./configure --prefix=/usr/local/nginx

    make&&make install  

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@bai usr]# nginx -s stop停止nginx
[root@bai usr]# nginx 运行nginx
[root@bai usr]# nginx -s reload 重启nginx
[root@bai 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才能生效。
 

转载:http://blog.csdn.net/shruby/article/details/41703881

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值