//启动 进入sbin ./nginx -c /develop/ngninx/config/nginxg 重启 ./nginx -s reload
#使用root启动防止一些访问静态资源403的报错
user root;
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;
client_max_body_size 30M;
#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;
#配置网址直接进入tomcat的一个项目,如果配置多个 复制多个server即可
server {
listen 80;
server_name chaoxiangzu.com www.chaoxiangzu.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://localhost:8080/hengshun-chaoxiangzu/dist/;
index index.html index.htm;
#这个必须要配置 不配置可能发生错误
autoindex off;
}
#js代理相关
location /js/ {
proxy_pass http://120.24.216.83:8100/dist/js/;
}
}
server {
listen 80;
server_name www.hhhax.cn h5.hhhax.cn;
location / {
proxy_pass http://localhost:7991/;
root /dist/;
index index.html index.htm index;
autoindex off;
}
<!--这边配置一个可以访问的外部外部文件夹 h5.hhhax.cn/upload/xxxx-->
location /upload/ {
alias /develop/VIDEO/;
autoindex on;
}
}
<!--配置https 要开放443 端口-->
server {
listen 443 ssl;
server_name www.nst.im nst.im;
ssl_certificate /develop/nginx/crt/nst.im.pem;
ssl_certificate_key /develop/nginx/crt/nst.im.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;
location / {
proxy_pass http://localhost:8089/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
root /dist/;
index index.html index.htm index;
autoindex off;
}
}
server {
listen 80;
server_name www.nst.im nst.im;
rewrite ^(.*) https://$server_name$1 permanent;
}
#一个比较常规的配置相关 访问域名直接到首页 然后访问端口 域名也隐藏
upstream adminupstream {
# 这边配置的是负载均衡相关 可以配置 多个 写down 就是停止相关 还需要注意 vue 的访问路径为www.adm.hoperbit.com(ps看是否有代理相关)
server localhost:8083 down;
}
server {
listen 80;
server_name www.adm.hoperbit.com adm.hoperbit.com;
location / {
root /develop/ziguan/web/admin;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /admin/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://adminupstream/admin/;
}
}
#配置一段相同域名根据设备不同访问不同页面 pc和h5
upstream loveminerhashratecloudwebstream{
server localhost:18082;
}
server {
listen 80;
server_name www.loveminer.cloud;
location / {
set $rewrite_loadurl "/develop/loveminer_hashrate_cloud/web/loveminer_hashrate_cloud_web";
if ( $http_cookie ~* "ACCESS_TERMINAL=mobile" ) {
set $rewrite_loadurl "/develop/loveminer_hashrate_cloud/web/loveminer_hashrate_cloud_h5";
}
if ($http_user_agent ~* (android|ip(ad|hone|od)|kindle|blackberry|windows\s(ce|phone))) {
set $rewrite_loadurl "/develop/loveminer_hashrate_cloud/web/loveminer_hashrate_cloud_h5";
}
root $rewrite_loadurl;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://loveminerhashratecloudwebstream/;
}
location /websocket/ {
proxy_pass http://loveminerhashratecloudwebstream/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120s;
proxy_set_header Upgrade websocket;
proxy_set_header Connection Upgrade;
}
}
#这边这样配置可以把每个网站的nginx的配置分开 ,方便以后维护
include /www/server/panel/vhost/nginx/*.conf;
}