所以,需要把是上面的server{...}拷贝一份,只需要把里面的localhost全部改成你的电脑ip就可以了,最终代码:
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 10;
- server {
- listen 80;
- server_name localhost;
-
- location =/ {
- add_header X-Frame-Options SAMEORIGIN;
- root D:/workspace/;
- index index.html;
- }
-
- location ~* .(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|swf|woff|woff2|ttf|json|svg|cur|vue|otf|eot)$ {
- charset utf-8;
- root D:/workspace/;
- expires 3d;
- }
-
- location = /socket/v2 {
- proxy_pass http://test.com;
- proxy_redirect off;
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection "upgrade";
- proxy_set_header Host test.com;
- 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_connect_timeout 30;
- proxy_send_timeout 30;
- proxy_read_timeout 60;
- proxy_buffer_size 256k;
- proxy_buffers 4 256k;
- }
-
- location / {
- proxy_pass http://test.com;
- proxy_set_header Cookie $http_cookie;
- proxy_cookie_domain test.com localhost;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header Host test.com;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header REMOTE-HOST $remote_addr;
- }
- }
- server {
- listen 8080;
- server_name xx.xx.xx.xx;
-
- location =/ {
- add_header X-Frame-Options SAMEORIGIN;
- root D:/workspace/;
- index index.html;
- }
-
- location ~* .(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|swf|woff|woff2|ttf|json|svg|cur|vue|otf|eot)$ {
- charset utf-8;
- root D:/workspace/;
- expires 3d;
- }
-
- location = /socket/v2 {
- proxy_pass http://test.com;
- proxy_redirect off;
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection "upgrade";
- proxy_set_header Host test.com;
- 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_connect_timeout 30;
- proxy_send_timeout 30;
- proxy_read_timeout 60;
- proxy_buffer_size 256k;
- proxy_buffers 4 256k;
- }
-
- location / {
- proxy_pass http://test.com;
- proxy_set_header Cookie $http_cookie;
- proxy_cookie_domain test.com xx.xx.xx.xx;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header Host test.com;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header REMOTE-HOST $remote_addr;
- }
- }
- }
访问方法:http://xx.xx.xx.xx:8080 即可 (编辑:南平站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|