当前位置: 首页 > article >正文

Nginx-基本安装

1.安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
2.安装PCRE

PCRE的作用是让Nginx支持Rewrite功能。

  1. 下载PCRE安装包
cd /opt
wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.44/pcre-8.44.tar.gz --no-check-certificate
  1. 解压安装包
tar zxvf pcre-8.44.tar.gz
  1. 进入安装包目录
cd pcre-8.44
  1. 编译安装
./configure
make && make install
  1. 查看pcre版本
pcre-config --version
3.安装Nginx

nginx网址(如果文档中下载的版本有问题可自行下载新版):
https://nginx.org/en/download.html

  1. 下载Nginx
cd /opt
wget https://nginx.org/download/nginx-1.24.0.tar.gz
  1. 解压安装包
tar zxvf nginx-1.24.0.tar.gz
  1. 进入解压后文件目录
cd nginx-1.24.0
  1. 编译安装(注意命令中–prefix=后跟的路劲为nginx编译安装后的服务器文件目录,–with-pcre=后的路劲为安装pcre的目录)
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/opt/pcre-8.44
make && make install
  1. 查看Nginx版本
/usr/local/webserver/nginx/sbin/nginx -v
4.Nginx配置
  1. 创建Nginx运行使用的用户nginx
groupadd nginx
useradd -g nginx nginx
chown -R nginx:nginx /usr/local/webserver/nginx
  1. 配置nginx.conf
#user  nobody;
user  nginx nginx; #定义运行的用户和组
worker_processes  1; #进程数,建议与CPU数相同#error_log  logs/error.log;
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #设置日志位置和日志级别,由高到低,[ debug | info | notice | warn | error | crit ]#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;
pid        /usr/local/webserver/nginx/nginx.pid; #进程pid文件worker_rlimit_nofile 65535; #指定进程可以打开的最多文件数目events {#use epoll; #参考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ],建议使用epollworker_connections  1024; #单个进程的最大连接数
}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; #sendfile指令指定 nginx 是否调用sendfile 函数(zero copy 方式)来输出文件,对于普通应用,必须设为on。如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络IO处理速度,降低系统uptime。#tcp_nopush     on; #此选项允许或禁止使用socke的TCP_CORK的选项,此选项仅在使用sendfile的时候使用#keepalive_timeout  0; keepalive_timeout  65; #长连接超时时间,单位秒#gzip  on; #开启gzip压缩输出server {listen       80; #监听端口server_name  localhost; #域名可以有多个,用空格隔开#charset koi8-r; #编码方式#access_log  logs/host.access.log  main; #定义本虚拟主机的访问日志location / {root   html;#index  index.html index.htm;try_files $uri $uri/ /index.html; #解决部署后刷新页面返回错误页面问题}#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;#    }#}}
  1. 检查配置文件nginx.conf的正确性命令
/usr/local/webserver/nginx/sbin/nginx -t
5.启动Nginx
  1. 启动
/usr/local/webserver/nginx/sbin/nginx
  1. 查看状态
ps -ef|grep nginx
6.访问站点
http://172.30.250.21/
7.Nginx的其他常用命令
/usr/local/webserver/nginx/sbin/nginx -s reload            # 重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reopen            # 重启 Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop              # 停止 Nginx
http://www.lryc.cn/news/2416958.html

相关文章:

  • Windows Vista 系统中的用户帐户控制和UAC远程限制 设置
  • 总线概述及常见总线
  • 基于JAVAWeb+Tomcat+Mysql开发的微电影网站
  • Java 常用代码汇总-附源码
  • C语言之文件读写——fscanf(),fprintf()详解
  • mailbox机制实例介绍(一)
  • 线性代数——余子式
  • HCIP------ 网络类型 PPP协议和HDCL协议
  • TrueCrypt原理与系统开发
  • 数据增强 - Cutout、Random Erasing、Mixup、Cutmix
  • 探索 `mpvue-vant`: 微信小程序开发的新利器
  • mint-ui使用
  • JqGrid 各个属性、方法使用说明
  • 快速上手 Rook,入门云原生存储编排
  • xxxxxxxxxxxxxxxxxxxxx已转行
  • ROV简易组装说明
  • 还在为没有项目做发愁?这几个神级开源网站,都是FPGA/IC项目
  • segment fault异常及常见定位手段
  • 分享几个源码网站奉献给大家(持续更新中……)
  • 【pmcaff】重磅干货,必读的扁平化设计技巧
  • GNS3 网络模拟器介绍
  • MySQL数据类型简介以及MySQL INT、TINYINT、SMALLINT、MEDIUMINT、BIGINT(整数类型)
  • WSUS补丁服务器搭建和使用(超详细+域策略设置)
  • Web前端最新jQuery UI widget源码解析,前端入门
  • Linux之常用压缩解压缩命令
  • 最近成果
  • AXIOM的介绍与使用
  • 天呐!你知道MSBuild都干了些什么
  • KingbaseES数据库审计
  • NDK基础