linux使用nginx配置web服务器
环境: CenterOS 7
1.安装nginx之前先安装nginx所需的依赖包
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
2.使用wget下载nginx压缩文件,并且解压安装,操作步骤如下:
点击查看官网nginx版本,此处我使用的是1.16.1版本
[root@VM_1_14_centos ~]# cd /data/
[root@VM_1_14_centos data]# wget http://nginx.org/download/nginx-1.15.7.tar.gz
[root@VM_1_14_centos data]# tar -xvf nginx-1.16.1.tar.gz
[root@VM_1_14_centos data]# mkdir //usr/local/nginx -p
[root@VM_1_14_centos data]# ll
total 1008
drwxr-xr-x 9 1001 1001 4096 Dec 17 15:16 nginx-1.15.7
-rw-r--r-- 1 root root 1026732 Nov 27 22:51 nginx-1.15.7.tar.gz
[root@VM_1_14_centos data]# cd nginx-1.15.7/
[root@VM_1_14_centos nginx-1.15.7]# ./configure --prefix=/usr/local/nginx
[root@VM_1_14_centos nginx-1.15.7]#make&&make install
3.nginx配置文件 (nginx默认已经配置好了,需要改的话请看下面带'#'的描述)
[root@VM_1_14_centos /]# cd /usr/local/nginx/conf/
[root@VM_1_14_centos conf]#
[root@VM_1_14_centos conf]#
[root@VM_1_14_centos conf]#
[root@VM_1_14_centos conf]# vim nginx.conf #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 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;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 80; #这里需要我们设置web访问的端口
server_name localhost; #这里设置web访问的IP,最终在浏览器访问;默认为localhost 也可以设置成服务器的ip,如129.xxx.xxx.xxx #charset koi8-r; #access_log logs/host.access.log main; location / { #这里配置nginx页面访问跳转
root html; #这里更重要,root是指直接访问 IP:port 时,获取文件的根目录,如果上一行设置为 / ,则直接访问IP:port会去拉取 /html下面的index.html
index index.html index.htm; #接上一行,如果location后面设置了目录 /abc ,则访问IP:port时,会拉取 /html/abc/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;
# }
#} }
4.启动nginx服务
[root@VM_1_14_centos sbin]# pwd
/usr/local/nginx/sbin
[root@VM_1_14_centos 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@VM_1_14_centos sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf #使用上一步配置的nginx.conf启动nginx服务
[root@VM_1_14_centos sbin]# ps -aux | grep nginx
root 6341 0.0 0.0 20552 620 ? Ss 16:04 0:00 nginx: master process ./nginx -c /usr/local/nginx/conf/nginx.conf
nobody 6342 0.0 0.0 23088 1396 ? S 16:04 0:00 nginx: worker process
root 6360 0.0 0.0 112708 980 pts/1 S+ 16:05 0:00 grep --color=auto nginx
5.打开浏览器,输入服务器上对应的ip地址和端口即可看见nignx默认的页面

这样就配置成功了nginx
linux使用nginx配置web服务器的更多相关文章
- 【CentOS 7】nginx配置web服务器
1,安装过程 [root@VM_1_14_centos ~]# cd /data/ [root@VM_1_14_centos data]# wget http://nginx.org/download ...
- nginx配置web服务器
一:设置虚拟服务器 1.设置 http { server { listen 127.0.0.1:8080; server_name example.org www.example.org; } } 2 ...
- nginx高性能WEB服务器系列之六--nginx负载均衡配置+健康检查
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- nginx高性能WEB服务器系列之五--实战项目线上nginx多站点配置
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- NGINX高性能Web服务器详解(读书笔记)
原文地址:NGINX高性能Web服务器详解(读书笔记) 作者:夏寥寥 第4章 Nginx服务器的高级配置 4.1 针对IPv4的内核7个参数的配置优化 说明:我们可以将这些内核参数的值追加到Linu ...
- nginx配置图片服务器
这几天研究了一下nginx配置图片服务器的相关内容,个人的一些收获与大家分享一下: Nginx是目前非常流行的web服务器,它起源于俄罗斯.它具有处理速度快,并发量大,占用资源极低等优点,尤其对于静态 ...
- centos从头学习配置web服务器环境
为了学习linux下配置web服务器环境,于是安装了vmware,准备在虚拟机里面学习web服务器的搭建! 首先是在虚拟机里安装centos,我选择的是32位的centos6.6版本,因为新版本7据说 ...
- Nginx高性能web服务器详解书中概要
一.Nginx功能 1.Nginx服务器以其功能丰富著称于世.它既可以作为HTTP服务器,也可以作为反向代理服务器或者邮件服务器;能够快速响应静态页面(HTML)的请求;支持FastCGI.SSL.V ...
- 【转】Linux下nginx配置https协议访问的方法
一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...
随机推荐
- 代码托管至Github
昨天突然之间觉得作为一个iOS程序员,没有在github上提交过自己的代码真是一大遗憾,不管是自己写的优秀的代码还是刚开始学习,用来学习练手的项目.然后我就很想要学习怎么往github上提交代码,很不 ...
- 来聊聊JavaScript中的防抖和节流
目录 JavaScript防抖和节流 问题还原 防抖 什么是防抖 使用场景 节流 什么是节流 使用场景 JavaScript防抖和节流 问题还原 我们先来通过代码把常见的问题还原: <html& ...
- 架构模式: 命令查询职责分离 (CQRS)
架构模式: 命令查询职责分离 (CQRS) 问题 如何在微服务架构中实现查询 结论 将应用程序拆分为两部分:命令端和查询端.命令端处理创建,更新和删除请求,并在数据更改时发出事件.查询端通过对一个或多 ...
- 关于python脚本头部设置#!/usr/bin/python
今天又是贼几把菜的一天0.0 读别人程序的时候看到在python文件头部设置签名,感觉贼几把酷,自己也试着在文件前段设置了一下. 设置还是蛮简单的,设置过程如图所示. 设置后如图所示: 当然你也可能看 ...
- Fabric Raft机制理解
为了不被无缘无故甩锅锅,这个我要好好理解下.
- Windows 下部署 hadoop spark环境
一.先在本地安装jdk 我这里安装的jdk1.8,具体的安装过程这里不作赘述 二.部署安装maven 下载maven安装包,并解压 设置环境变量,MAVEN_HOME=D:\SoftWare\Mave ...
- Windows冷门快捷键
Win+Shift+>或者+<光标键,可以使一个程序,在双屏显示器上左右切换. alt+space快捷键相当于在窗口的标题栏上面右键单击,弹出菜单,选择M键,就可以使用光标键上下左右移动来 ...
- 【ActiveReports 大数据分析报告】2019国庆旅游出行趋势预测
今年国庆假期全国接待国内游客人数有望达到8亿人次! 随着2019国庆小长假的临近,不少游客已经开始着手规划假期出游路线.据权威机构发布的<2019国庆旅游趋势预测报告>显示,今年“十一黄金 ...
- 啃掉Hadoop系列笔记(02)-Hadoop运行环境搭建
一.新增一个普通用户bigdata
- winform中如何使用timer控件实现欢迎(初始加载)窗口
第一步.新建窗体项目命名为:TestWelcomeFrm,如下图: 第二步.在新项目中,增加欢迎窗口,命名为WelFrm,整个项目目录如下: 第三步.修改program.cs中启动代码如下: WelF ...