linux安装nginx

1.前提准备

安装编译工具及库文件

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

gcc、gcc-c++ # 主要用来进行编译相关使用
openssl、openssl-devel # 一般当配置https服务的时候就需要这个了
zlib、zlib-devel # 主要用于文件的解压缩
pcre、pcre-devel # Nginx的rewrite模块和HTTP核心模块会用到PCRE正则表达式语法

make # 遍历

make install # 安装

2.下载解压nginx

cd /usr/local/ngin
// wget https://nginx.org/download/nginx-1.18.0.tar.gz  #下载(有了就不用下载)
tar -zxvf nginx-1.18.0.tar.gz   #解压

或者nginx下载地址:http://nginx.org/download/ (将下载的nginx导入到服务器中)
进入安装包目录

cd nginx-1.9.9

编译安装nginx,默认安装到 /usr/local/nginx中

//编译
./configure --prefix=/usr/local/nginx
 //安装
make && make install

先找一下nginx安装到什么位置上了

[root@localhost nginx-1.9.9]# whereis nginx
nginx: /usr/local/nginx

3.配置和验证

在nginx.conf中简单配置

server {
        listen       80;
        server_name  localhost;
        location / {
            root   /usr/local/web/dist;
            index  index.html index.htm;
        }
        # 静态资源目录,在对应目录先建好文件夹
        location /admintest {
            alias   /usr/local/web/admin/dist;
            index  index.html index.htm;
        }
        #代理node服务
        location /api {
            proxy_pass http://127.0.0.1:3002;
        }
   }

同一ip配置多个域名

server{
    listen 80;
    server_name www.aaa.com; #绑定域名
    index index.htm index.html index.php; #默认文件
    root /home/web/dist; #网站根目录
    error_page 404 /404.html;#添加404网页
}
 
server{
    listen 80;
    server_name www.bbb.com; #绑定域名
    index index.htm index.html index.php; #默认文件
    root /home/web/dist1; #网站根目录
}
#不带www的域名加301跳转
server{
    listen 80;
    server_name bbb.com;
    rewrite ^/(.*) http://www.bbb.com/$1 permanent;
}

查看nginx.conf配置是否正确

/usr/local/nginx/sbin/nginx -t

[root@localhost sbin]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
//代表成功

启动,重启,停止nginx

cd /usr/local/nginx/sbin/
./nginx   #启动
./nginx -s stop  #停止
./nginx -s quit  #退出
./nginx -s reload  #重启  修改配置后重新加载生效<br><br>./nginx -s reopen :重新打开日志文件<br>

启动后查看进程

 
kill -QUIT 主进程号   #从容停止
 
kill -TERM 主进程号  #快速停止
 
kill -9 主进程号  #强制停止

问题

我们Linux系统在安装应用程序时进行指定其安装目录 ,通常使用 ./configure --prefix=自定义的安装目录 命令来操作。

例如我安装python应用使用

./configure --prefix=/home/softwareInstall/pythoninstall 

错误提示:./configure报

-bash: ./configure: No such file or directory

分析原因:
1、在你配置指定路径时没有这样的文件或目录存在,先创建一个目录。
2、可能现在执行的目录下没有configure 程序,你无法执行,你到configure所在目录下重新执行语句就可以了

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容