0
点赞
收藏
分享

微信扫一扫

Linux Nginx配置文件

钟罗敏 2022-12-31 阅读 162

第一部分:Nginx目录

Linux 部署Nginx以后目录如图:

Linux Nginx配置文件_html

 

 

 其中:

conf:Nginx配置文件目录,里面存放着Nginx配置文件

conf.d:(自定义的配置)Nginx配置文件目录,用于存放自定义的Nginx配置文件

html:Nginx默认的html

logs:Nginx日志文件

nginx-1.18.0:Nginx安装目录

sbin:Nginx启动目录,启动Nginx,需要进入sbin,通过./nginx启动

第二部分:Nginx配置

2.1 conf 目录

Linux Nginx配置文件_html_02

 

 

 2.2 conf 目录下存在两个文件:nginx.conf和nginx.conf.default,default为默认配置不作修改,只需要修改nginx.conf:

#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;

include /usr/local/nginx/conf.d/*.conf;

}

第三部分:自定义的配置

3.1 conf.d 目录

Linux Nginx配置文件_nginx_03

 

 3.2 需要自定义一个default.conf用于监听80端口,否则会出现ip访问后默认80端口缺少监听,随机分发给某个监听的配置,default.conf:

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
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;
}


}

3.3 根据实际需要自定义配置:eypg.conf

upstream 1yyg {
ip_hash;
server 13.229.77.133:8081 weight=10;
#server 127.0.0.1:8082 weight=3;
#server 127.0.0.1:8083 weight=4;
}

server {
listen 80;
server_name www.shweshan.com shweshan.com;

#允许最大上传1M图片
client_max_body_size 5M;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
proxy_pass http://1yyg;
}

#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;
}

}

3.4 根据实际需要自定义配置:wygw.conf

upstream wygw {
ip_hash;
server 13.229.77.133:8082 weight=10;
}

server {
listen 80;
server_name www.microplaymm.com microplaymm.com;

#允许最大上传1M图片
client_max_body_size 5M;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
proxy_pass http://wygw;
}

#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;
}

}

根据实际需要监听,只需要将配置文件放到conf.d目录即可。

 

举报

相关推荐

0 条评论