linux环境下安装nginx步骤

1、YUM安装

参考 http://www.cnblogs.com/wutengbiao/p/4188986.html

2、gcc g++开发类库安装

yum install gcc gcc-c++

3、make编译环境安装

yum -y install gcc automake autoconf libtool make

4、安装PCRE库

cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz 
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.34
./configure
make
make install

5、安装zlib库

cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install

6、安装openssl

cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar -zxvf openssl-1.0.1t.tar.gz
cd openssl-1.0.1t
./config
make
make install

7、安装nginx

cd /usr/local/src
wget http://nginx.org/download/nginx-1.1.10.tar.gz
tar -zxvf nginx-1.1.10.tar.gz
cd nginx-1.1.10
./configure
make
make install

8、编辑配置文件

nginx解压路径下的conf文件,/usr/local/nginx/conf/nginx.conf
(1)修改域名为 hello.yanan.com
(2)配置tomcatIP端口 10.10.10.10:8080
(3)配置访问路径为 域名加后缀 /index.jsp

    server {
        listen       80;
        server_name  hello.yanan.com *. hello.yanan.com;

        rewrite_log on;

        if ($host ~ ^(.*)\. hello.yanan.com){
                set $user $1;
        }

        location = / {
                    rewrite ^ /index.jsp;
                }

        location ~* (.*)\.(gif|jpg|jpeg|png|css|js|ico)$ {
           proxy_pass http://10.10.10.10:8080/$1.$2;
        }

        location / {
            rewrite ^(.*)$ $1?user=$user break;
            proxy_pass http://10.10.10.10:8080/;
            proxy_set_header  Host             $host;
            proxy_set_header  X-Real-IP        $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
        }

9、配置本地host文件

在hosts文件(C:\Windows\System32\drivers\etc\hostsni)中配置IP、域名

10.10.10.10 hello.yanan.com

10、启动tomcat及nginx

浏览器中输入地址即可。如:hello.yanan.com
nginx启动服务

[root@test ~]# cd /usr/local/nginx/sbin
[root@test sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

Nginx服务启动报错解决方法
在这里插入图片描述

11、Nginx停止服务

[root@test ~]# ps -axu | grep nginx
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      4675 0.0  0.0 103308   828 pts/0    R+   13:20   0:00 grep nginx
root     25476  0.0  0.0  19732   612 ?        Ss   Aug04   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   24784 0.0  0.0  20148  1676 ?        S    Aug04   0:05 nginx: worker process        
[root@test  ~]# kill -TERM 25476  

12、Nginx关闭服务

[root@test  ~]# kill -9 25476  

13、Nginx重启服务

[root@test ~]# cd /usr/local/nginx/sbin
[root@test sbin]#./nginx -s reload
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值