服务器 nginx 配置

一般目录地址:
/etc/nginx

nginx.conf 配置示例

# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user www-data;
worker_processes auto;
worker_rlimit_nofile 65535;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
# include /usr/share/nginx/modules/*.conf;

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 100;
types_hash_max_size 2048;
client_max_body_size 100m;
underscores_in_headers on;

server_names_hash_max_size 1024;
server_names_hash_bucket_size 64;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /404.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }

}

conf.d 文件夹配置示例

# 文件名起 xxx.conf
# 配置示例
# jenkins.conf 示例
server {
listen 80;
server_name jenkins.xxx.xxx.xxx;

access_log /etc/nginx/logs/jenkins.access.log main;
error_log /etc/nginx/logs/jenkins.error.log warn;

location / {
proxy_pass http://localhost:8080;
}
}
# 站点配置示例
# xxx.conf
server {
listen 80;
server_name ~^([a-zA-Z0-9-]+)\.pda-dev\.xxx(域名配置)\.xxx(域名配置)\.xxx(域名配置)$;
set $platform $1;

charset utf-8;
access_log /etc/nginx/logs/pda.admin.dev.access.log main;
error_log /etc/nginx/logs/pda.admin.dev.error.log error;

location @rewrites {
rewrite ^.*$ /index.html last;
}

location /api {
proxy_pass http://api.pda-dev-admin.xxx(域名配置);
}

location / {
root /mnt/data/www/frontend_deploy_workspace/dev/pda/$platform;
try_files $uri $uri/ @rewrites;
index index.html;
}
}