linux 系统nginx 安装
2020-09-07 本文已影响0人
一蓑烟雨_龙哥
nginx 官网
http://nginx.org/en/download.html
yum 安装
image.png选择centos 结合官网看。注意版本7 指的的centos 的版本,7或者7.x ,8或者8.x 都可以。
image.png安装好后,查看版本。
[root@VM-0-2-centos ~]# nginx -v
nginx version: nginx/1.18.0
nginx -V 显示编译的参数。
[root@VM-0-2-centos ~]# nginx -V
yum 安装好nginx 后,用 rpm -ql nginx 查询安装的目录
[root@localhost yum.repos.d]# rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/modules
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
nginx 的启动,停止,重启
########关闭
service nginx stop
systemctl stop nginx
########启动
service nginx reload
systemctl restart nginx
#########随系统启动自动运行
systemctl enable nginx
#######禁止随系统启动自动运行
systemctl disable nginx
########
nginx 启动后,输入ip,如下表示 启动成功。
image.png
知识点扩展:
首先利用配置文件启动nginx。
[命令](https://www.linuxcool.com/ "命令"):
首先利用配置文件启动nginx。
[命令](https://www.linuxcool.com/ "命令"):
nginx -c /usr/local/nginx/conf/nginx.conf
重启服务: service nginx restart
1. 快速停止或关闭Nginx:nginx -s stop
2. 正常停止或关闭Nginx:nginx -s quit
3. 配置文件修改重装载[命令](https://www.linuxcool.com/ "命令"):nginx -s reload
image.png
[root@VM-0-2-centos conf.d]# cat default.conf
#代表服务配置
server {
listen 80; #端口配置
server_name localhost; #服务器名
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
#当用户访问http://ip:80/
location / {
root /usr/share/nginx/html; #当匹配到/这个规则时(因为location 后面是 /),指向目录/usr/share/nginx/html。
index index.html index.htm; #当访问不指定具体页面时,默认显示的页面,类似于 web.xml 的 welcomefiles;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#当服务出现500的错误时,访问的页面。
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/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;
#}
}