安装前准备工作

因为Nginx依赖于gcc的编译环境,所以,需要安装编译环境来使Nginx能够编译起来

yum install gcc-c++

Nginx的http模块需要使用pcre来解析正则表达式,需要安装pcre

yum install -y pcre pcre-devel

安装依赖的解压包

yum install -y zlib zlib-devel

ssl 功能需要 openssl 库,安装 openssl

yum install -y openssl openssl-devel

下载Nginx

可以自己建立一个包,将nginx下载到这个路径,我设置的路径/opt/crm/nginx
如果需要其他nginx版本的可以参考 nginx仓库

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

下载完之后解压

tar zxvf nginx-1.10.2.tar.gz

进入到解压之后的nginx目录

[root@localhost src]# cd nginx-1.10.2
[root@localhost nginx-1.10.2]# ./configure && make && make install

如果要使用ssl

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

注意:如果配置了ssl,检查配置文件时报错

nginx -t
nginx:[emerg]unknown directive ssl错误去到nginx安装的目录
./configure --with-http_ssl_module注意要把新生成的文件复制到对应目录
cp objs/nginx /usr/local/nginx/sbin/nginx显示成功就搞定
[root@iZ2ze02hshpth1x0vxo8r6Z 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
[root@iZ2ze02hshpth1x0vxo8r6Z sbin]#

安装完之后查看安装目录

[root@izbp10k7vskcf4soxxbp5gz /]# whereis nginx
nginx: /usr/local/nginx
[root@izbp10k7vskcf4soxxbp5gz /]#

通过查找文件名方式

[root@izbp10k7vskcf4soxxbp5gz /]# find / -name nginx
/opt/crm/nginx
/opt/crm/nginx/nginx-1.10.2/objs/nginx
/usr/local/nginx
/usr/local/nginx/sbin/nginx
[root@izbp10k7vskcf4soxxbp5gz /]#

直接执行

[root@izbp10k7vskcf4soxxbp5gz /]# /usr/local/nginx/sbin/nginx
[root@izbp10k7vskcf4soxxbp5gz /]# ps -ef | grep nginx
root      4666     1  0 09:32 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody    4667  4666  0 09:32 ?        00:00:00 nginx: worker process
root      5028 29443  0 09:40 pts/0    00:00:00 grep --color=auto nginx
[root@izbp10k7vskcf4soxxbp5gz /]#

在浏览器输入服务器IP地址

增加systemctl命令方式启动

直接启动和关闭nginx的方式

启动nginx的命令为     /usr/local/nginx/sbin/nginx
停止nginx的命令为    /usr/local/nginx/sbin/nginx -s stop
重启nginx的命令为    /usr/local/nginx/sbin/nginx -s reload

配置方式 去到/usr/lib/systemd/system/目录新建一个nginx服务,给予执行权限

vim /usr/lib/systemd/system/nginx.service
chmod +x /usr/lib/systemd/system/nginx.service

打开文件nginx.service新建内容

[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target   [Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true                                                                  [Install]
WantedBy=multi-user.target

保存之后重载Ststemctl命令

在启动服务之前,需要先重载systemctl命令
systemctl daemon-reload

配置完之后

systemctl status nginx
systemctl start nginx
systemctl stop nginx
systemctl restart nginx

附上配置

#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  65535;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;gzip    on;#允许压缩的最小字节数gzip_min_length 1k;#4个单位为16k的内存作为压缩结果流缓存gzip_buffers 4 16k;#设置识别HTTP协议版本,默认是1.1gzip_http_version 1.1;#gzip压缩比,可在1~9中设置,1压缩比最小,速度最快,9压缩比最大,速度最慢,消耗CPUgzip_comp_level 2;#压缩的类型gzip_types text/plain application/x-javascript text/css application/xml;#让前端的缓存服务器混村经过的gzip压缩的页面gzip_vary   on;# 配置转发到8700 端口upstream  huida{server  127.0.0.1:8700;}server {listen       80;listen       443 ssl;                      # 配置https,监听433端口server_name  xxx.xxx;                    # 注意如果申请了域名配置再此,如果配置了证书才能https访问error_page 405 =200 $request_uri;ssl_certificate  cert/7629385.pem;ssl_certificate_key cert/7629385.key;client_max_body_size 50m;underscores_in_headers on;proxy_set_header Host      $host;proxy_set_header  X-Real-IP        $remote_addr;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;index index.htm index.html index.php;proxy_connect_timeout 60; #建立tcp协议的连接时间proxy_send_timeout 60;    #发送接口的时间proxy_read_timeout 60;    #读取时间(接口响应时间)#charset koi8-r;#access_log  logs/host.access.log  main;# 配置转发location /huida/ {add_header 'Access-Control-Allow-Origin' '*';add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Token';add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Token';proxy_pass http://huida;}location / {root   /home/html/huida/;index  index.html index.htm;}#静态文件交给nginx处理 代理前端静态资源location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)${root /home/html/huida/;expires 12;}#静态文件交给nginx处理location ~ .*\.(js|css)?${root /home/html/huida/;expires 15d;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}

解决nginx:unknown directive ssl错误

Linux安装Nginx并配置启动命令相关推荐

  1. linux安装nginx并配置域名映射和图片服务器

    环境:阿里云轻量级云服务器 操作系统:centos7 背景: 在上一篇博客阿里云服务器部署SpringBoot项目(mysql安装.服务部署)(https://blog.csdn.net/zwx199 ...

  2. Linux安装nginx并配置ssl

    在linux下安装nginx,首先需要安装 gcc-c++编译器.然后安装nginx依赖的pcre和zlib包.最后安装nginx即可. 1.先安装gcc-c++编译器 yum install gcc ...

  3. Linux安装Nginx以及配置前端项目

    下载安装先配置环境 yum install gcc-c++ yum -y install pcre pcre-devel yum -y install zlib zlib-devel yum inst ...

  4. Linux安装Nginx 作者:哇塞大嘴好帅

    Linux安装Nginx 作者:哇塞大嘴好帅 作者:哇塞大嘴好帅哇塞大嘴好帥 1.环境确保工作 如果ls等指令失效输入 export PATH=$PATH:/usr/local/sbin:/usr/l ...

  5. Windows安装nginx并配置端口转发

    Windows安装nginx并配置端口转发 1.场景 在VMware虚拟机中启动了几个Linux,采用的是NAT网络配置,所以另一个Windows访问无法进行ssh或者其它应用的访问 2.安装 2.1 ...

  6. linux安装nginx教程

    linux安装nginx教程 安装依赖包 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel 下载安装包 # 我是装 ...

  7. 服务器搭建--Linux安装nginx

    安装所需环境 Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境. 一. gcc 安装 安装 nginx 需要 ...

  8. linux添加cfg,Linux安装详解-配置ks.cfg实现自动安装过程

    Linux安装详解-配置ks.cfg实现自动安装过程 之前发过一篇关于通过PXE实现Linux批量无人值守自动安装的文章(可以参考),不过写的只是具体的配置和操作,对于原理部分没有说明,最近通过一段时 ...

  9. Linux 安装 nginx 详细教程

    文章目录 Linux 安装 nginx 详细步骤 ①安装依赖包 ②下载并解压安装包 ③安装 nginx ④启动 nginx 服务 ⑤nginx 反向代理 提示:以下是本篇文章正文内容,Linux 系列 ...

最新文章

  1. lnamp环境搭建博客、论坛
  2. 关于SQL 数据库表中的聚集索引和非聚集索引等
  3. 维护库存地点的装运点确认
  4. poj 2057 树形DP,数学期望
  5. SQl常用语句总结(持续更新……)
  6. 捷达vs7测试_捷达VS7——品质硬核!
  7. 垃圾收集 java_关于Java垃圾收集
  8. C语言基础知识(一)-------C++语言结构
  9. 2.5配置自定义HttpMessageConverters
  10. VSCode解决设置默认浏览器方法(open with live server)
  11. 服务器系统在虚拟机安装win7系统安装教程,虚拟机安装教程图解 虚拟机安装win7步骤...
  12. 阅读笔记——凤凰架构(第1章)
  13. 【学英语~磨耳朵】2013年以来看过的所有美剧电影纪录片等等
  14. word怎么转pdf原格式不变?可以试试这个途径
  15. vue 修改模板{{}}标签_vue.js - Vue单文件的template标签
  16. Excel+VBA+之快速上手
  17. 北京师范大学新闻与传播专硕考研一战上岸经验分享
  18. Ray Tracing(扩展欧几里得,ax+by=c最小解)
  19. liunx查看ftp服务器文件目录,linux查看ftp服务器目录
  20. 驼峰式与下划线命名规则

热门文章

  1. 自学管理学有哪些书籍值得推荐?
  2. 【备忘录】为Windows10 LTSC 安装应用商店和XBOX
  3. 怎样恢复出厂设置并还原Apple Silicon M1 Mac?
  4. 李彦宏:外面的世界很大眼界决定命运
  5. 一加9pro 鸿蒙系统,Mate40Pro对比一加9Pro:差距无法接受
  6. 怎么对oracle 进行重装,重装oracle的方法
  7. 词源学习法第一集---election
  8. Pixhawk原生固件PX4之驱动ID
  9. 原创海洋cmsv10视频站模板大气自适应酷黑色星空主题下载
  10. 音频-DSD-Delta-Sigma