linux安装配置nginx

linux安装配置nginx

安装依赖软件

yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

安装nginx

//下载软件
wget http://nginx.org/download/nginx-1.13.7.tar.gz
//解压
tar zxvf nginx-1.13.7.tar.gz
//创建安装目录
mkdir -p /usr/local/nginx
//修改配置
cd nginx-1.13.7/
在编译的时候 需要配置 ssl支持
./configure --prefix=/usr/local/nginx --with-http_ssl_module
如果不需要,则用下面命令
./configure --prefix=/usr/local/nginx
//安装
make && make install

启动nginx

进入安装目录
cd /usr/local/nginx/sbin
启动
./nginx

配置

修改/usr/local/nginx/conf/nginx.conf

server {
listen 9091;#监听端口
server_name 47.107.83.5;#ip地址
# gzip config
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable “MSIE [1-6].”;

root /usr/share/nginx/html;

location / {
    # 用于配合 browserHistory 使用
index index.html index.htm index.jsp;
proxy_pass http://localhost:9090;#前端界面地址

    #try_files $uri $uri/ /index.html;

    # 如果有资源,建议使用 https + http2,配合按需加载可以获得更好的体验 
    # rewrite ^/(.*)$ https://preview.pro.loacg.com/$1 permanent;

}
location /api {
    proxy_pass http://localhost:9090/server/api;#后台接口地址
    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;
}

}

报错

如果启动nginx报错:Nginx: [error] open() "/usr/local/Nginx/logs/Nginx.pid" failed(2:No such file or directory)
解决方法:运行此命令:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

命令

进入nginx/sbin目录下
./nginx 启动
./nginx -s -reload 重启
./nginx -s stop 关闭

备注

毛都没有~~~~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值