现在同一linux服务器配置其端口的服务,拟用已经运行 的nginx来配置
步骤如下
创建一个配置文件 比如 /usr/local/nginx/sites-available/gaotianyue.conf
upstream gaotianyue.com{ server 127.0.0.1:8070 weight=1; } server { listen 8071; server_name localhost; location / { proxy_http_version 1.1; proxy_pass http://gaotianyue.com; proxy_redirect default; proxy_connect_timeout 1s; proxy_read_timeout 5s; proxy_send_timeout 2s; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; add_header 'Access-Control-Allow-Headers' 'Content-Type'; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET'; } location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|mp3|mp4)$ { root /data/gaotianyue/static_src; expires 14d; } error_page 404 /404.html; error_page 404 /404.html; location = /404.html{ root html; } error_page 500 503 504 /50x.html; location = /50x.html { root html; } error_page 502 /502.html; location = /502.html{ root html; } } 修改nginx.conf最后一个括号前添加
include /usr/local/nginx/sites-available/*.conf; } 然后检查下 [root@VM_126_4_centos nginx]# sbin/nginx -t -c conf/nginx.conf nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful最后重启
sbin/nginx -s reload