nginx 1

简介: nginx

环境准备

配置epel仓库源

wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
#如果提示未找到命令 使用yum install wget -y 安装一下wget
#安装bash* -y 补全命令提示
#关闭防火墙和开机自启
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
#关闭selinux
[root@localhost /]# setenforce 0 #临时关闭
#修改配置文件永久关闭
[root@localhost /]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled #改成 disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are
protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@localhost /]#

安装nginx

yum install nginx -y #安装nginx
#启动nginx开启开机自启
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to
/usr/lib/systemd/system/nginx.service.
#查看nginx状态
[root@localhost ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset:
disabled)
Active: active (running) since 三 2023-07-12 08:53:49 CST; 36s ago
Main PID: 14813 (nginx)
CGroup: /system.slice/nginx.service
├─14813 nginx: master process /usr/sbin/nginx
├─14814 nginx: worker process
├─14815 nginx: worker process
├─14816 nginx: worker process
└─14817 nginx: worker process
7月 12 08:53:48 localhost.localdomain systemd[1]: Starting The nginx HTTP and
reverse proxy server...
7月 12 08:53:49 localhost.localdomain nginx[14808]: nginx: the configuration file
/etc/nginx/nginx.conf syntax is ok
7月 12 08:53:49 localhost.localdomain nginx[14808]: nginx: configuration file
/etc/nginx/nginx.conf test is successful
7月 12 08:53:49 localhost.localdomain systemd[1]: Started The nginx HTTP and
reverse proxy server.

yum安装的nginx配置文件都在/etc/nginx/

nginx配置文件

user nginx; #启动用户
worker_processes auto; #子进程数
error_log /var/log/nginx/error.log; #错误的日志
pid /run/nginx.pid; #进程pid
include /usr/share/nginx/modules/*.conf; #加载配置文件
events {
worker_connections 1024; #连接数
}
http {
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 /var/log/nginx/access.log main; #成功的日志
sendfile on; #零复刻
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types; #加载文件
default_type application/octet-stream; #数据类型
include /etc/nginx/conf.d/*.conf; #加载文件
服务 虚拟主机 应用程序
server {
listen 80; #端口
listen [::]:80; #ipv6端口
server_name _; #域名 主机名
root /usr/share/nginx/html; #发布目录 程序的目录
error_page 404 /404.html; #如果服务器状态码是404 就会把404.html文件返回给
我们
location = /404.html {
}
error_page 500 502 503 504 /50x.html;#如果服务器状态码是500 502 503 504 就
会把50x.html文件返回给我们
location = /50x.html {
}
}
}

添加虚拟主机

#不同端口 同主机名添加虚拟主机
#vim 打开/etc/nginx/nginx.conf
#在第一个server后面添加下面内容
server {
listen 90; #端口号不能冲突
server_name _; #域名,主机名
root /usr/share/nginx/xiaole;#发布目录
}
#相同端口不同域名添加虚拟主机
server {
listen 80; #端口是80
server_name xiaole.com; #域名,主机名
root /usr/share/nginx/xiaole;#发布目录
}
#如需访问需要添加在hosts添加一条解析
#Linux hosts文件在/etc/hosts
#windows host文件 在C:\Windows\System32\drivers\etc\hosts


相关实践学习
基于函数计算快速搭建Hexo博客系统
本场景介绍如何使用阿里云函数计算服务命令行工具快速搭建一个Hexo博客。
相关文章
|
23天前
|
负载均衡 JavaScript 应用服务中间件
nginx使用
nginx使用
|
9月前
|
负载均衡 应用服务中间件 nginx
nginx V1.0
nginx V1.0
|
9月前
|
缓存 负载均衡 应用服务中间件
Nginx
当今互联网时代,网站的高性能和稳定性是至关重要的。为了实现这一目标,服务器软件起着举足轻重的作用。在众多服务器软件中,Nginx(发音为"engine-x")以其出色的性能、可靠性和灵活性而脱颖而出,成为了许多网站和应用程序的首选。本文将深入介绍Nginx,从其起源、特点,以及如何安装和配置等方面,为您全面解析这一强大的服务器软件。
89 0
|
缓存 负载均衡 算法
Nginx——详解
Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的。从2004年发布至今,凭借开源的力量,已经接近成熟与完善。
123 0
Nginx——详解
|
缓存 负载均衡 前端开发
|
Web App开发 负载均衡 前端开发
nginx使用分享
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like协议下发行。Nginx的并发能力在同类型的Web服务器中表现优异,国内主流无论大小互联网公司都在用。
571 0
nginx使用分享
|
网络协议 应用服务中间件 网络安全
Nginx 实现OCSP Stapling
详解Nginx 如何实现OCSP Stapling
834 0
|
应用服务中间件 开发工具 nginx
Nginx之15独孤九剑 - (GoogleFilter)
Nginx从入门到深入之Google Proxy
1036 0
|
应用服务中间件 nginx
Nginx 速度限制
                      这篇文章主要介绍了Nginx限制带宽配置示例,本文网罗了3个方法,希望可以帮到大家,需要的朋友可以参考: 示例一: 复制代码代码如下: http { limit_rate 25k;              ...
1110 0