Linux安装Nginx

作者:Keysqiu
创建时间:2025-11-30 18:19:01 最后一次修改时间:2025-12-02 17:59:11
Categories: Tags:

1、安装依赖和相关库:

yum -y install gcc-c++ zlib-devel openssl-devel libtool

2、下载nginx安装包并解压:

cd /usr/local
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar -zxvf nginx-1.14.0.tar.gz

3、配置和安装

cd nginx-1.14.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install

vue dist nginx配置:(在/usr/local/nginx/conf/的nginx.conf里面)

location / {
            root /home/server/dist;
            index index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
##后台
location /api{
  proxy_pass http://服务器IP:后台端口号/;
}

4、启动nginx: (在/usr/local/nginx/sbin/里面)

cd ../nginx/sbin
./nginx

5、查看nginx:

ps -ef | grep nginx

结果如下所示

root 13850 1 0 17:01 ? 00:00:00 nginx: master process ./nginx

nobody 13851 13850 0 17:01 ? 00:00:00 nginx: worker process

root 13879 1128 0 17:11 pts/0 00:00:00 grep --color=auto nginx

6、停止和重启nginx: (在/usr/local/nginx/sbin/里面)

./nginx -s reload   #重启
./nginx -s stop #关闭