獲取鏡像:php
docker pull nginx:1.15html
運行node
docker run \ --name nginx \ -p 443:443 \ -p 80:80 \ -v /usr/local/nginx/html/:/usr/share/nginx/html:ro \ -v /usr/local/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \ -v /usr/local/nginx:/var/run \ -v /usr/local/nginx/logs/:/var/log/nginx/:rw \ -v /usr/local/nginx/ssl/:/ssl/:ro \ -v /usr/local/nginx/include:/etc/nginx/include \ -d nginx:1.15
日誌文件位置:/var/log/nginx
配置文件位置: /etc/nginx
資源存放的位置: /usr/share/nginx/htmlnginx
ssl 配置
docker
docker run \ --name nginx \ -p 443:443 \ -p 80:80 \ -v /usr/local/nginx15/html/:/usr/share/nginx/html:ro \ -v /usr/local/nginx15/nginx.conf:/etc/nginx/nginx.conf:ro \ -v /usr/local/nginx15:/var/run \ -v /usr/local/nginx15/logs/:/var/log/nginx/:rw \ -v /usr/local/nginx15/ssl/:/ssl/:ro \ -d nginx:1.15
server { listen 80; listen 443 ssl; #ssl on; #若是強制HTTPs訪問,這行要打開 server_name xx.xx.com; ssl_certificate /ssl/a.pem; ssl_certificate_key /ssl/a.key; #ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; root html; index index.html index.htm; location / { proxy_pass http://16.114.21.135:8881; } }
nginx.confbash
注意 配置文件中不能直接使用 127.0.0.1 和 localhsot 來識別宿主IPsession
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { 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/mime.types; default_type application/octet-stream; # 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; server { listen 80 default_server; listen [::]:80 default_server; server_name 182.254.161.54; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_pass http://pic; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } upstream pic{ server 182.254.161.54:8088 weight=5; server 182.254.161.54:8089 weight=5; } }
二app
#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; server { listen 80 default_server; server_name 78.141.56.17; root /usr/share/nginx/html; #charset koi8-r; #access_log logs/host.access.log main; location / { 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; } # 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; # } #} server { listen 80; server_name www.tse-xxa.com; root html; index index.html index.htm; location / { proxy_pass http://47.171.16.17:8889; } } # 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; # } #} }