Skip to main content

nginx配置文件

nginx网站默认存放位置

/usr/share/nginx/html

nginx配置文件

位置在 /etc/nginx/nginx.conf 默认配置

cat /etc/nginx/conf.d/default.conf

内容

error_log  /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/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 /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}

只需把自己的.conf 放入 /etc/nginx/conf.d/ 文件夹下就行了

一个 Go 的配置文件

server {
listen 80;
server_name local.video.asdasd.cn;
charset utf-8;
access_log /data/logs/video.asdasd.cn.access.log;
location / {
proxy_pass http://127.0.0.1:8080;
}
}

负载均衡的话要这么写

upstream mysrv{
ip_hash;
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
server {
listen 80;
server_name local.video.asdasd.cn;

location / {
try_files /_not_existes_@backend;
}
location / {
proxy_pass http://mysrv;
}
}