nginx安装过程及常用命令

1 Linux安装

执行yum install yum-utils

运行vim /etc/yum.repos.d/nginx.repo
输入:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

然后查看源
yum list | grep nginx
看到存在稳定版的源,确认无误。

运行安装命令
yum install nginx
过程中输入y,确认

查看版本,若出现版本号,则安装成功
nginx -v
whereis nginx可以查看到目录:
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz

2 Mac OS的安装

安装homebrew,然后nginx使用安装brew:
$ brew install nginx
后续按提示安装即可,通常zoo.conf是直接配置好的。

3 Windows下的安装不推荐

注:在浏览器中输入ip测试是否安装成功,如果无法访问计得检查防火墙配置,是否开放80端口。

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --reload
firewall-cmd --zone=public --list-ports
nginx -s stop 
nginx -s quit
nginx -s reload

stop强制停止,quit优雅停止(已建立连接会在服务结束后停止,即已建立的连接不会收到影响)

修改配置文件

cd /etc/nginx
vim nginx.conf
cd /etc/nginx/conf.d
vim default.conf

nginx.conf:

# 运行用户
user  nginx;
# 工作进程数,可以和CPU核心数一致
worker_processes  1;
# 错误日志路径
error_log  /var/log/nginx/error.log;
pid      /run/nginx.pid;
# 把对应的配置文件导入
include /usr/share/nginx/modules/*.conf;
events {
# 连接数
    worker_connections  1024;
}
# http服务器的配置
http {
# 访问日志
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
# keepalive超时时间
    keepalive_timeout  65;
#加载其他各模块的配置文件
include /etc/nginx/conf.d/*.conf;
    server {
#监听端口号
        listen       80;
        listen       [::]:80;
        server_name  _;
    #root路径的位置
        root         /usr/share/nginx/html2;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值