1. 程式人生 > >Nginx 服務搭建

Nginx 服務搭建

參考:http://blog.csdn.net/ysydao/article/details/51388385
搭建完成需要進行業務配置
upstream upstream_zhishimao{
        server 127.0.0.1:8081;
        }

server{
        listen 80;
        listen 443 ssl;
        ssl_certificate /data/keys/domain.crt;
        ssl_certificate_key     /data/keys/server.key;
        server_name api2.zhishimao.cn;
        charset utf-8
; root /datat/app/html; index index.html index.htm; # add_header Access-Control-Allow-Origin '*'; add_header Access-Control-Allow-Origin 'http://h52.zhishimao.cn'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods'
'GET, POST, DELETE, PUT, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'Accept, Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; location / { if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin'
'http://h52.zhishimao.cn'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, PUT, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'Accept, Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Content-Length' 0; return 204; } proxy_pass http://upstream_zhishimao; proxy_redirect off; 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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_max_temp_file_size 0; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_temp_file_write_size 64k; } } server { charset utf-8; listen 80; #listen 443 ssl; server_name h52.zhishimao.cn; #ssl_certificate /usr/local/webserver/cert/h5domain.crt; #ssl_certificate_key /usr/local/webserver/cert/h5server.key; root /data/html/zhishimaokouyu-wx/; index index.html; location / { try_files $uri $uri/ /data/html/zhishimaokouyu-wx/index.html; } } upstream upstream_projects{ server 127.0.0.1:9000; } server { listen 80; server_name pro.zhishimao.cn; index index.html; location / { if ( $request_uri = "/" ) { rewrite "/" http://pro.zhishimao.cn:9000/zentaopms/www/index.php break; } #proxy_pass http://pro.zhishimao.cn:9000; proxy_pass http://upstream_projects; } } 配置成功後還有可能出現500 Internal Server Error 可參考 https://www.kafan.cn/edu/80525056.html