Hello everyone,
I'm currently using Cloudflare for SaaS. I've configured everything correctly in Cloudflare, and I'm able to use a custom domain. However, I'm facing a problem. I can only open the homepage, but when I try to click on any post, I get the following error:
"Oops! Something went wrong during a cross - origin request. Please reload the page and try again."
I asked an AI for help, and it suggested adding the following configuration to my Nginx:
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
}
}
After making this change, I encountered an Nginx error:
nginx: [emerg] duplicate location "/" in /www/server/panel/vhost/nginx/example.com.conf:43
nginx: configuration file /www/server/nginx/conf/nginx.conf test failed
I've double - checked my configuration file, but I can't find a duplicate location / block. Could anyone please help me figure out what's going wrong? How can I fix the cross - origin request issue and resolve this Nginx configuration error?
Here is my current Nginx configuration file (a part of it):
server {
listen 80;
listen 443 ssl http2;
server_name example.com www.example.com biubbs.top;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/example.com/public;
include /www/wwwroot/example.com/.nginx.conf;
#SSL-START SSL related configuration, do not delete or modify the commented 404 rule below
#error_page 404/404.html;
#HTTP_TO_HTTPS_START
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
#HTTP_TO_HTTPS_END
ssl_certificate /www/server/panel/vhost/cert/example.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/example.com/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
error_page 497 https://$host$request_uri;
#SSL-END
#Quote redirection rules, the configured redirection proxy will be invalid after commenting
include /www/server/panel/vhost/nginx/redirect/example.com/*.conf;
#ERROR-PAGE-START Error page configuration, can be commented, deleted or modified
# #error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP reference configuration, can be commented or modified
include enable-php-81.conf;
#PHP-INFO-END
#REWRITE-START URL rewrite rule reference, modification will cause the pseudo-static rules set by the panel to be invalid
include /www/server/panel/vhost/rewrite/example.com.conf;
#REWRITE-END
# Other configurations...
}
Any help would be greatly appreciated!
Best regards,
biubiu