02-001 Docker 啟動 Nginx

  1. nginx 部署安裝
    • 創(chuàng)建目錄
mkdir -p /opt/nginx/{conf,html,logs}
- 添加配置文件
vim /opt/nginx/conf/nginx.conf
user root;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    upstream api.phjrstbt.com {
        server 210.210.210.202:8080 weight=1;    #此處ip為服務(wù)器內(nèi)網(wǎng)IP,端口號為tomcat端口號
    }
    server {
        listen       8083;
        server_name  html5;

        location ~ .*\.(js|css|ico|png|jpg|eot|svg|ttf|json|woff|html|json)$ {
            root /usr/share/nginx/html/html5;
            expires 30d; #緩存30天
        }
        location / {
            proxy_pass http://api.phjrstbt.com/;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen       8082;
        server_name  api;
        location /prod-api/ {
                proxy_pass http://api.phjrstbt.com/;
        }
        location /download {
                root /home/ftpuser; #配置下載文件的路徑
                autoindex on;    #開啟索引功能
                autoindex_exact_size off;  #關(guān)閉計(jì)算文件確切大?。▎挝籦ytes),只顯示大概大?。▎挝籯b、mb、gb)
                autoindex_localtime on;   #顯示本機(jī)時(shí)間而非 GMT 時(shí)間
        }

        location / {
                root /usr/share/nginx/html/phjrstbt/dist;
                try_files $uri $uri/ @router;
                index  index.html index.htm;
                expires 30d; #緩存30天
        }
        location @router {
            rewrite ^.*$ /index.html last;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

啟動命令

docker run -d --restart=always --name nginx -p 8082:8082 -p 8083:8083 \
--privileged=true \
-v /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /opt/nginx/logs:/var/log/nginx \
-v /opt/nginx/html:/usr/share/nginx/html \
nginx

https

# 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/doc/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 {
#        # 監(jiān)聽 80 端口
#        listen 80;
#        autoindex on;
#        client_max_body_size 20m;
#        server_name *.zhongxinda.top;
#        index index.html index.htm index.jsp index.php;
#        rewrite ^(.*)$ https://$host$1 permanent;
#        if ( $query_string ~* ".*[\;'\<\>].*" ){
#            return 404;
#        }
#        location / {
#            # 反向代理到 8080 端口
#            proxy_set_header Host $host;
#            proxy_pass http://127.0.0.1:7777/;
#            add_header Access-Control-Allow-Origin *;
#        }
#
#    }


    server {
        listen 443 ssl; #配置HTTPS的默認(rèn)訪問端口號為443。此處如果未配置HTTPS的默認(rèn)訪問端口,可能會造成Nginx無法啟動。Nginx 1.15.0以上版本請使用listen 443 ssl代替listen 443和ssl on。
        server_name *.zhongxinda.top; #將www.certificatestests.com修改為您證書綁定的域名,例如:www.example.com。如果您購買的是通配符域名證書,要修改為通配符域名,例如:*.aliyun.com。
        ssl_certificate /etc/nginx/cert/5209268_zhongxinda.top.pem;  #將domain name.pem替換成您證書的文件名稱。
        ssl_certificate_key /etc/nginx/cert/5209268_zhongxinda.top.key; #將domain name.key替換成您證書的密鑰文件名稱。
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #使用此加密套件。http://127.0.0.1:9999/
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用該協(xié)議進(jìn)行配置。
        ssl_prefer_server_ciphers on;
        location /apple-app-site-association{
            root /usr/share/nginx/html;
            index wxpay.json;
        }
        location /xxl-job-admin{
            proxy_set_header Host $host;
            proxy_pass http://47.102.150.203:11111/xxl-job-admin/;
            add_header Access-Control-Allow-Origin *;
        }

        location /prod-api/ {
            proxy_set_header Host $host;
            proxy_pass http://47.102.150.203:7777/;
            add_header Access-Control-Allow-Origin *;
        }

       location / {
           root /usr/share/nginx/html/web/dist;
           try_files $uri $uri/ @router;
           index  index.html index.htm;
           expires 30d; #緩存30天
       }
       location @router {
           rewrite ^.*$ /index.html last;
       }
    }

}


啟動命令


docker run -d --restart=always --name nginx -p 80:80 -p 443:443 \
--privileged=true \
-v /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /opt/nginx/logs:/var/log/nginx \
-v /opt/nginx/html:/usr/share/nginx/html \
-v /opt/nginx/cert:/etc/nginx/cert/ \
nginx
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容