nginx官网安装教程

安装教程目录

安装

  • Install the prerequisites
sudo yum install yum-utils
  • To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
  • By default, the repository for stable nginx packages is used. If you would like to use mainline nginx packages, run the following command:
sudo yum-config-manager --enable nginx-mainline
  • To install nginx, run the following command:
sudo yum install nginx

When prompted to accept the GPG key, verify that the fingerprint matches 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62, and if so, accept it.

相关路径

  • nginx
/usr/sbin/nginx
  • nginx.conf
/etc/nginx/nginx.conf
  • 前端文件
/usr/share/nginx
  • 错误日志
/var/log/nginx/error.log
  • 访问日志
/var/log/nginx/access.log

相关命令(Linux)

启动命令

/usr/sbin/nginx

停止命令

/usr/sbin/nginx -s stop

重新载入

/usr/sbin/nginx -s reload

运行

  • 设置开机启动nginx
sudo systemctl enable nginx.service

卸载

yum remove nginx

相关命令(Windows)

启动命令

start nginx

停止命令

nginx.exe -s stop

nginx.exe -s quit

注:stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息。

重新载入

nginx.exe -s reload

当配置信息修改,需要重新载入这些配置时使用此命令。

重新打开日志文件

nginx.exe -s reopen

查看Nginx版本:

nginx -v

https://www.cnblogs.com/ryanzheng/p/11263031.html

面试题

Nginx代理后如何获取客户端真实IP地址

https://www.jb51.net/server/285630mpb.htm

03-20 15:36