点赞
评论
收藏
分享
举报
centOS7安装nginx及nginx配置
发表于2020-09-02 16:11

浏览 4.8k

安装所需插件

1、安装gcc

gcc是linux下的编译器在此不多做解释,感兴趣的小伙伴可以去查一下相关资料,它可以编译 C,C++,Ada,Object C和Java等语言

命令:查看gcc版本 

gcc -v

一般阿里云的centOS7里面是都有的,没有安装的话会提示命令找不到,

安装命令:

yum -y install gcc

2、pcre、pcre-devel安装

pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库。

安装命令:

yum install -y pcre pcre-devel

3、zlib安装

zlib库提供了很多种压缩和解压缩方式nginx使用zlib对http包的内容进行gzip,所以需要安装

安装命令:

yum install -y zlib zlib-devel

4、安装openssl

openssl是web安全通信的基石,没有openssl,可以说我们的信息都是在裸奔。。。。。。

安装命令:

yum install -y openssl openssl-devel

安装nginx

1、下载nginx安装包

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

2、把压缩包解压到usr/local/java

tar -zxvf  nginx-1.9.9.tar.gz

3、切换到cd /usr/local/java/nginx-1.9.9/下面

执行三个命令:

  1. ./configure
  2. make
  3. make install

5、切换到/usr/local/nginx安装目录

6、配置nginx的配置文件nginx.conf文件,主要也就是端口

可以按照自己服务器的端口使用情况来进行配置

ESC键,wq!强制保存并退出

7、启动nginx服务

切换目录到/usr/local/nginx/sbin下面

启动nginx命令:

./nginx

8、查看nginx服务是否启动成功

ps -ef | grep nginx

9、访问你的服务器IP

显示

说明安装和配置都没问题OK了

nginx.conf说明

  1. #user nobody;
  2. worker_processes 1; #工作进程:数目。根据硬件调整,通常等于cpu数量或者2倍cpu数量。
  3. #错误日志存放路径
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7. #pid logs/nginx.pid; # nginx进程pid存放路径
  8. events {
  9. worker_connections 1024; # 工作进程的最大连接数量
  10. }
  11. http {
  12. include mime.types; #指定mime类型,由mime.type来定义
  13. default_type application/octet-stream;
  14. # 日志格式设置
  15. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  16. # '$status $body_bytes_sent "$http_referer" '
  17. # '"$http_user_agent" "$http_x_forwarded_for"';
  18. #access_log logs/access.log main; #用log_format指令设置日志格式后,需要用access_log来指定日志文件存放路径
  19. sendfile on; #指定nginx是否调用sendfile函数来输出文件,对于普通应用,必须设置on。
  20. 如果用来进行下载等应用磁盘io重负载应用,可设着off,以平衡磁盘与网络io处理速度,降低系统uptime。
  21. #tcp_nopush on; #此选项允许或禁止使用socket的TCP_CORK的选项,此选项仅在sendfile的时候使用
  22. #keepalive_timeout 0; #keepalive超时时间
  23. keepalive_timeout 65;
  24. #gzip on; #开启gzip压缩服务
  25. #虚拟主机
  26. server {
  27. listen 80; #配置监听端口号
  28. server_name localhost; #配置访问域名,域名可以有多个,用空格隔开
  29. #charset koi8-r; #字符集设置
  30. #access_log logs/host.access.log main;
  31. location / {
  32. root html;
  33. index index.html index.htm;
  34. }
  35. #错误跳转页
  36. #error_page 404 /404.html;
  37. # redirect server error pages to the static page /50x.html
  38. #
  39. error_page 500 502 503 504 /50x.html;
  40. location = /50x.html {
  41. root html;
  42. }
  43. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  44. #
  45. #location ~ \.php$ {
  46. # proxy_pass http://127.0.0.1;
  47. #}
  48. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  49. #
  50. #location ~ \.php$ { #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
  51. # root html; #根目录
  52. # fastcgi_pass 127.0.0.1:9000; #请求转向定义的服务器列表
  53. # fastcgi_index index.php; # 如果请求的Fastcgi_index URI是以 / 结束的, 该指令设置的文件会被附加到URI的后面并保存在变量$fastcig_script_name中
  54. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  55. # include fastcgi_params;
  56. #}
  57. # deny access to .htaccess files, if Apache's document root
  58. # concurs with nginx's one
  59. #
  60. #location ~ /\.ht {
  61. # deny all;
  62. #}
  63. }
  64. # another virtual host using mix of IP-, name-, and port-based configuration
  65. #
  66. #server {
  67. # listen 8000;
  68. # listen somename:8080;
  69. # server_name somename alias another.alias;
  70. # location / {
  71. # root html;
  72. # index index.html index.htm;
  73. # }
  74. #}
  75. # HTTPS server
  76. #
  77. #server {
  78. # listen 443 ssl; #监听端口
  79. # server_name localhost; #域名
  80. # ssl_certificate cert.pem; #证书位置
  81. # ssl_certificate_key cert.key; #私钥位置
  82. # ssl_session_cache shared:SSL:1m;
  83. # ssl_session_timeout 5m;
  84. # ssl_ciphers HIGH:!aNULL:!MD5; #密码加密方式
  85. # ssl_prefer_server_ciphers on; # ssl_prefer_server_ciphers on; #
  86. # location / {
  87. # root html;
  88. # index index.html index.htm;
  89. # }
  90. #}
  91. }
已修改于2023-03-09 02:03
创作不易,留下一份鼓励
张东明001

暂无个人介绍

关注



写下您的评论
发表评论
全部评论(0)

按点赞数排序

按时间排序

关于作者
张东明001
这家伙很懒还未留下介绍~
19
文章
1
问答
15
粉丝
相关文章
系统层优化系统socket层优化echo65535>/proc/sys/net/core/somaxconn 准许最大链接数echo1>/proc/sys/net/ipv4/tcp_tw_recycle 快速回收链接echo1>/proc/sys/net/ipv4/tcp_tw_reuse  重用链接echo0>/proc/sys/net/ipv4/tcp_syncookies 关闭洪水抵御系统文件层优化ulimit-n65535nginx配置层优化nginxsocket层优化 worker_connections 10240;nginx层打开文件数优化worker_rlimit_nofile20000;ab-n500000-c20000 http://192.168.1.52/index.htmlServerSoftware:    nginx/1.10.2ServerHostname:    192.168.1.52ServerPort:      80DocumentPath:
点赞 4
浏览 1k
一、下载Nginx源文件因为安装模块需要重新编译,编译需要用到Nginx的源文件,所以这里还要下载一份。下载地址:http://nginx.org/en/download.htmlcd/usr/local/src wgethttp://nginx.org/download/nginx-1.12.2.tar.gz tar-xvfnginx-1.12.2.tar.gz二、下载安装LuaJITngx_lua_waf官方推荐LuaJIT2.1版本(2.0或者2.1都是支持的)下载地址:http://luajit.org/download.htmlcd/usr/local/src wgethttp://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz tar-zxfLuaJIT-2.1.0-beta3.tar.gz cdLuaJIT-2.1.0-beta3 makePREFIX=/usr/local/luajit makeinstallPREFIX=/usr/local/luajit三、下载ngx_devel_kit
点赞 2
浏览 1.4k
用户任务1: 累计发表5篇原创文章,点击任务在评论区写下您的原创文章链接; l LV3用户等级权益: 社区官网个人主页展示精美V3等级勋章1个; 有机会在社区官网首页“社区达人”模块展示您的个人主
点赞 0
浏览 406