docker 安装部署 nginx
命令
docker run \
-p 15008:80 \
--name nginx1.21.6 \
-v /iepms/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /iepms/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /iepms/nginx/log:/var/log/nginx \
-v /iepms/nginx/html:/usr/share/nginx/html \
-d 192.168.1.103/base/nginx:1.26.1
nginx 配置文件
#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;
#include ./conf/include/blackIP.conf;
include D:/tool/nginx/nginx-1.26.1/conf/include/blackIP.conf;
client_max_body_size 10m;
client_body_buffer_size 10m;
#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
gzip on;
#低于1kb的资源不压缩
gzip_min_length 1k;
#压缩级别1-9,越大压缩率越高,同时消耗cpu资源也越多,建议设置在5左右。
gzip_comp_level 5;
#需要压缩哪些响应类型的资源,多个空格隔开。不建议压缩图片.
#gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;
#配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
gzip_disable "MSIE [1-6]\.";
#是否添加“Vary: Accept-Encoding”响应头
gzip_vary on;
gzip_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;
# 代理服务器
upstream backend {
ip_hash;
server localhost:8089 max_fails=1000 weight=1;
server localhost:8088 weight=1000;
}
server {
listen 80;
server_name 127.0.0.1;
server_name_in_redirect on;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/;
index index.html index.htm;
}
#location /image {
# root html/;
# index index.html index.htm;
#}
#location /image {
# root html/;
# try_files $uri $uri/ /image/default.jpg;
#}
location ~* \.(gif|jpg|jpeg|png|bmp)$ {
valid_referers 127.0.0.1;
if ($invalid_referer) {
return 403;
#可以配置成返回一张禁止盗取的图片
#rewrite ^/ https://xxxxxxxxxxx
}
}
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
add_header Access-Control-Allow-Origin *;
proxy_pass http://backend/;
}
location /iepms_web_test {
root html/;
proxy_pass http://192.168.1.126:16008/iepms_web/;
try_files $uri $uri/ /iepms_web/default.jpg;
}
location /gateway/ {
proxy_hide_header X-Frame-Options;
add_header X-Frame-Options ALLOWALL;
proxy_pass http://127.0.0.1:15000;
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}