Skip to content

配置

server {
location / {
root /data/www;
}
location /images/ {
root /data;
}
}
server {
location / {
proxy_pass http://localhost:8080/;
}
location ~ \.(gif|jpg|png)$ {
root /data/images;
}
}
http {
upstream myapp1 {
# ip_hash;
server 127.0.0.1:8080 weight=3;
server srv2.example.com;
server srv3.example.com;
}
server {
listen 80;
location /app {
proxy_pass http://myapp1;
}
}
}
server {
listen 80;
listen 443 ssl;
server_name www.example.com;
return 301 https://$server_name$request_uri;
ssl_certificate www.example.com.crt;
ssl_certificate_key www.example.com.key;
...
}
server {
listen 5173;
server_name localhost;
location / {
root /sites/dist;
index index.html index.htm;
}
}
server {
listen 8080;
server_name localhost;
}
# user nginx;
worker_processes auto;
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
# 错误页
error_page 404 /404.html;
location = /40x.html {}
error_page 500 502 503 504 /50x.html;
location = /50x.html {}
}
}