单个域名
upstream web{ server 127.0.0.1:3000;//这里绑定你要访问的服务器地址 keepalive 64; } server { listen 80; server_name www.xxxx.con;//你的域名 #access_log /var/log/nginx/log/host.access.log main; #client_max_body_size 100m; location / { proxy_read_timeout 300; proxy_pass http://web;//绑定要访问的服务器地址也可以这里绑定,这里绑定就不用上面的upstream web了 proxy_set_header Host $http_host; } error_page 404 /404.html; location = /50x.html { root /usr/share/nginx/html; proxy_set_header Host $http_host; } }
多个域名绑定
这里演示的是一个conf文件里面配置多个server ,多个文件的没试过,暂时先用
#user nobody; 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; sendfile on; keepalive_timeout 65; #缓存配置 proxy_connect_timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; proxy_temp_path /home/temp_dir; proxy_cache_path /home/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=5g; #跨域配置 add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-HeadersX-Requested-With,Origin,
Content-Type, Accept
; add_header Access-Control-Allow-Methods GET,POST,OPTIONS,PUT,DELETE; #绑定域名 # 个人网站服务器 server { listen 80; server_name dev.hxh999.cn;#你的域名 #gzip压缩 gzip on; gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; #缓存配置 location ~ .*\.(gif|jpg|png|htm|html|css|js|flv|ico|swf|font|woff|tff|svg|eto)(.*) { proxy_pass http://127.0.0.1:9000; proxy_redirect off; proxy_set_header Host $host; proxy_cache cache_one; proxy_cache_valid 200 302 1d; proxy_cache_valid 301 3d; proxy_cache_valid any 1m; expires 7d; } location / { proxy_read_timeout 300; proxy_pass http://127.0.0.1:9000; proxy_set_header Host $http_host; } error_page 404 /404.html; location = /50x.html { root /usr/share/nginx/html; proxy_set_header Host $http_host; } } #测试服务器 server { listen 80; server_name www.hxh999.cn;#你的域名 #gzip压缩 gzip on; gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; #缓存配置 location ~ .*\.(gif|jpg|png|htm|html|css|js|flv|ico|swf|font|woff|tff|svg|eto)(.*) { proxy_pass http://127.0.0.1:8000; proxy_redirect off; proxy_set_header Host $host; proxy_cache cache_one; proxy_cache_valid 200 302 1d; proxy_cache_valid 301 3d; proxy_cache_valid any 1m; expires 7d; } location / { proxy_read_timeout 300; proxy_pass http://127.0.0.1:8000; proxy_set_header Host $http_host; } error_page 404 /404.html; location = /50x.html { root /usr/share/nginx/html; proxy_set_header Host $http_host; } } }
上面第二段代码可以直接放nginx.conf里面使用,配置一下你自己的要修改的地方
要修改的地方 有访问服务器的地址 端口 地址都是 本机 127.0.0.1 ,就是端口不一样
再有就是 绑定自己的域名,其他地方都是通用配置,跨域 压缩 缓存什么的,不用可以干掉 不会影响
绑定多个域名 就写多个server