Nginx的安装与初步使用
Nginx的安装与初步使用
Nginx的安装与初步使用
1. Nginx简介
Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日。
其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。
2. Nginx的安装
2.1 Linux环境
直接yum命令安装即可,不用下载源码编译
# 在阿里云的控制台直接yum安装即可
yum install nginx
其他安装方法可参见菜鸟教程
安装完成之后可以通过如下命令来验证是否安装成功
#查看Nginx版本
nginx -v
#查看Nginx安装位置
whereis nginx
2.2 Windows 环境
在Nginx官网下载Windows版本软件包。
3. Nginx的配置文件
Nginx的配置主要是修改nginx.conf文件,手动安装的在安装目录下面,自动安装的在/etc/ngixn
目录下面。
# 修改配置文件
vim /etc/nginx/nginx.conf
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 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 9527;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root D:/blog/public;
index index.html index.htm;
}
#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;
# }
#}
}
重点需要关注其中的server配置:
-
listen
就是访问端口,默认80
,我这里修改为8010
; -
server_name
是服务名称,可以写自己的域名,我这里填写本地localhost
; -
location
是指定资源名称,其中root
是指定主页目录地址,index
指定主页文件名称,这里配置的可以是index.html
或者index.htm
。
4. 启动Nginx,访问页面
在启动Nginx前需要通过名称验证配置文件是否正确
# 验证配置文件
nginx -t
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# nginx: configuration file /etc/nginx/nginx.conf test is successful
启动nginx,启动之后就可以通过地址和端口好访问查看nginx是否已经配置成功
# 启动nginx
nginx
5. Nginx的其他常用命令
# 重新载入配置文件
nginx -s reload
# 重启 Nginx
nginx -s reopen
# 停止 Nginx
nginx -s stop
原文地址:https://www.cnblogs.com/alltoforever/p/12680886.html
- 如何构建爬虫代理服务?
- (19) 接口的本质 / 计算机程序的思维逻辑
- (18) 为什么说继承是把双刃剑 / 计算机程序的思维逻辑
- 有效的python属性管理:描述符的使用
- (17) 继承实现的基本原理 / 计算机程序的思维逻辑
- (16) 继承的细节
- Python时间处理完全手册
- 计算机程序的思维逻辑 (15) - 初识继承和多态
- 前端自动化测试漫长路之——Selenium初探
- 计算机程序的思维逻辑 (14) - 类的组合
- webpack中tree-shaking技术介绍
- Python进行远程视频监控
- 好用的前端页面性能检测工具—sitespeed.io
- 计算机程序的思维逻辑 (13) - 类
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法