nginx cors配置

开启目录索引:autoindex  on;

1.nginx配置查看sock
1.1 sudo find /etc/php -type f -name '*.conf' -exec grep -H 'listen' {} \;

1.2 cat /etc/php/8.1/fpm/pool.d/www.conf
以下内容:
; Note: This value is mandatory.
listen = /var/run/php/php7.4-fpm.sock

可以改为ip端口监听:

listen = 127.0.0.1:9002

server {

        listen        80;

        server_name  www.goserver.com;

        # root   "E:/projects/www.goserver.com";

        location / {

            # 设置允许跨域头部

            add_header 'Access-Control-Allow-Origin' 'http://www.vuedist.com';

            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

            # cookies跨域传输

            add_header 'Access-Control-Allow-Credentials' true;

            add_header 'Access-Control-Allow-Headers' 'Origin,x-token, Authorization, Accept, DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

           

            # 如果请求方法为 OPTIONS,则直接返回 204 状态码

            if ($request_method = 'OPTIONS') {

                add_header 'Access-Control-Allow-Origin' 'http://www.vuedist.com';

                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

                add_header 'Access-Control-Allow-Credentials' 'true';

                add_header 'Access-Control-Allow-Headers' 'Origin, Authorization, Accept, 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://localhost:8869;

            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_set_header X-Forwarded-Proto $scheme;

        }

-------------------------------------------------------------

        使用try_files指令可以提高性能,因为它允许Nginx直接服务静态文件(如CSS、JavaScript、图片等),而无需将这些请求传递给PHP解释器。这减少了服务器负载并加快了静态资源的加载速度

location / { try_files $uri $uri/ /index.php?$query_string; }

-------------------------------------------------------------

        location ~ \.php(.*)$ {

            fastcgi_pass   127.0.0.1:9001;

            fastcgi_index  index.php;

            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            fastcgi_param  PATH_INFO  $fastcgi_path_info;

            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;

            include        fastcgi_params;

        }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值