icecoder / ICEcoder

Browser code editor awesomeness
http://icecoder.net
Other
1.41k stars 348 forks source link

Page not loading with Nginx #997

Closed Klemich closed 2 years ago

Klemich commented 2 years ago

Hi, I'm running on Nginx, I installed php-fpm and it run form my root folder. I'm trying this from firefox, chrome and opera.

Describe the bug However, once I ask the my-domain.com/icecoder I end up on my website, and my-domain.com/icecoder/index.php transforms itself into /index.php/lib/login.php/lib/login.php and the page is in "working" state forever (more than 1hour at the last count). The text is showing, but nothing else.

The user set for the root and the icecoder is www-data:www-data and the folders are in 755 and files in 644 mod.

Can you help me ? Thanks

mattpass commented 2 years ago

@Klemich think this relates to the same problem you mentioned on another issue, where I suspected a session or path issue, it's looking ever more likely to be a path issue from description above. Is the document root is set to the dir where my-domain.com is hosted from? Do you have any nginx rules which change DOCUMENT_ROOT or SCRIPT_NAME to something unusual, or set a redirect of some sort?

(Technically, ICEcoder is a site within a site, so the web server setup for your site may be doing something unexpected. Looking at your nginx error logs may help to understand what's happening).

I would say that ICEcoder works fine with Nginx and Apache (the icecoder.net site uses Nginx) and over the years I've seen 100's of reports that it doesn't work with a server, but I can only remember maybe 5 that were actually ICEcoder code related. It's always a server settings issue, is just a case of figuring out what this is!

Would definitely suggest looking at Nginx settings for your domain and error logs too. The permissions are probably absolutely fine. (Though check to ensure www-data is definitely the userame expected for website files!)

Klemich commented 2 years ago

Hi, Thanks for your answer. Is the document root is set to the dir where my-domain.com is hosted from? Do you have any nginx rules which change DOCUMENT_ROOT or SCRIPT_NAME to something unusual, or set a redirect of some sort?

Can you be more specific about what you mean regarding the 'document root' ? I have a redirect from http to https, and another from my-domain.com to www.my-domain.com, would that cause such trouble ?

I would say that ICEcoder works fine with Nginx and Apache (the icecoder.net site uses Nginx) and over the years I've seen 100's of reports that it doesn't work with a server, but I can only remember maybe 5 that were actually ICEcoder code related. It's always a server settings issue, is just a case of figuring out what this is!

That's reassuring.

Though check to ensure www-data is definitely the userame expected for website files!

How do I do that ?

Here are the nginx config files : 1st, the nginx.conf :

user www-data;
 worker_processes  auto;

 error_log  /var/log/nginx/error.log notice;
 pid        /var/run/nginx.pid;

 events {
     worker_connections  1024;
 }

 http {
     include       /etc/nginx/mime.types;
     #include      /etc/nginx/sites-available/*.conf;
     #default_type  application/octet-stream;

     #root       /var/www;
     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';

     access_log  /var/log/nginx/access.log  main;

     sendfile        on;
     #tcp_nopush     on;

     keepalive_timeout  65;

     #gzip  on;

     include /etc/nginx/conf.d/*.conf;
 }

then the default :

server {
     server_name  my_domain.com;

     #access_log  /var/log/nginx/host.access.log  main;
     root /var/www/www.my_domain.com;
     index index.html index.php;

     location / {
         try_files $uri /index.html index.php =404;
     }

     # redirect server error pages to the static page /50x.html
     #
     error_page 500 502 503 504  /50x.html;
     location = /50x.html {
         root   /var/www/www.my_domain.com;
     }

     error_page 404 /40x.html;
     location = /40x.html {
         root   /var/www/www.my_domain.com;
     }

     # proxy the PHP scripts to Apache listening on 127.0.0.1:80
     #
     #location ~ \.php$ {
     #    proxy_pass   http://127.0.0.1;
     #}

     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     #
     location ~ [^/]\.php(/|$) {
         fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_index index.php;
         fastcgi_param PHP_VALUE open_basedir="/var/www/www.my_domain.com/:/var/www/www.my_domain.com/php/";
         include fastcgi_params;

     }
     # SCRIPT_FILENAME parameter is used for PHP FPM determining
     #  the script name. If it is not set in fastcgi_params file,
     # i.e. /etc/nginx/fastcgi_params or in the parent contexts,
     # please comment off following line:
     #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
     location ~ /\. { # le "~" indique une regex que "/" démarre, ici tout ce qui a un "." autre que php ou html
         deny all;
         access_log off;
         log_not_found off;
     }

     listen 443 ssl; # managed by Certbot
     ssl_certificate /etc/letsencrypt/live/my_domain.com/fullchain.pem; # managed by Certbot
     ssl_certificate_key /etc/letsencrypt/live/my_domain.com/privkey.pem; # managed by Certbot
     include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
     ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

 }

 server {
         listen 80;
         server_name www.my_domain.com;

         return 301 https://$server_name$request_uri; # redirets http requests to https website
 }

 server {
        listen 80;
        listen 443 ssl;
        server_name my_domain.com;
        return 301 http://www.my_domain.com$request_uri;
 }

Nginx error logs after today's attempt to connect :

2021/09/27 01:30:26 [error] 58243#58243: *27472 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 167.99.93.228, server: gout-cha.com, request: "GET /w
2021/09/27 02:57:21 [error] 58243#58243: *27482 access forbidden by rule, client: 45.61.175.11, server: gout-cha.com, request: "GET /.env HTTP/1.1", host: "47.242.156.85"
2021/09/27 03:49:58 [crit] 58243#58243: *27499 SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking, client: 192.241.208.178, server: 
2021/09/27 04:11:10 [error] 58243#58243: *27519 access forbidden by rule, client: 45.201.206.80, server: gout-cha.com, request: "GET /.env HTTP/1.1", host: "47.242.156.85"
2021/09/27 04:11:11 [error] 58243#58243: *27522 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 45.201.206.80, server: gout-cha.com, request: "GET /v
2021/09/27 04:40:56 [error] 58243#58243: *27531 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 202.65.145.140, server: gout-cha.com, request: "GET /
2021/09/27 10:43:15 [crit] 58243#58243: *27599 SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking, client: 184.105.247.252, server: 
2021/09/27 11:02:23 [error] 58243#58243: *27602 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 194.36.45.73, server: gout-cha.com, request: "GET /wp
2021/09/27 15:07:26 [crit] 58243#58243: *27634 SSL_do_handshake() failed (SSL: error:14201044:SSL routines:tls_choose_sigalg:internal error) while SSL handshaking, client: 213.32.122.82, server: 0.0.0.0:
Klemich commented 2 years ago

turns out I just needed to replace my try...line by try_files $uri $uri/ /index.php?$args =404; and add default_type text/php; after inside the location / {.

All working now, phpmyadmin too.