- nginx 部署安装
- 创建目录
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为服务器内网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; #关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
autoindex_localtime on; #显示本机时间而非 GMT 时间
}
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 {
# # 监听 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的默认访问端口号为443。此处如果未配置HTTPS的默认访问端口,可能会造成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; #使用该协议进行配置。
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