Author Topic: Nginx configure  (Read 4522 times)

0 Members and 2 Guests are viewing this topic.

Offline
*
Nginx configure
« on: June 17, 2022, 01:15:46 AM »
My Web Server is Nginx & Apache, I have several ULRs without suffix, for example: https://www.example.com/my-post

Please note that there is no "/" at the end of this URL. Now visiting this URL will directly display the source code of this page. How can I make it display the content of the page?

Offline
****
Re: Nginx configure
« Reply #1 on: June 17, 2022, 02:34:27 AM »
if you mean that it's a PHP page, you need FPM for nginx to use php.
Google Hangouts:  rcschaff82@gmail.com

Offline
*
Re: Nginx configure
« Reply #2 on: June 18, 2022, 04:11:50 AM »
It's not a PHP page, it's a static page, because an opencart was installed before, and its pages are without / at the end, I deleted opencart now, but there are a few pages that need to be kept, so I created these pages manually

How do I set up so that these pages can display the content, and now visit them only to display the source code

Actually, the FPM  has been installed

If the Web Server is switched to Apache Only, these pages can be displayed normally, but I am using Nginx & Apache now, I think it may be caused by Nginx.
« Last Edit: June 18, 2022, 04:16:21 AM by gailclark80 »

Offline
****
Re: Nginx configure
« Reply #3 on: June 18, 2022, 07:30:10 PM »
If html is displayed as source code, then the mime type for nginx is messed up.  Check for the default mime types and make sure it's not set to text/plain
Google Hangouts:  rcschaff82@gmail.com

Offline
*
Re: Nginx configure
« Reply #4 on: June 20, 2022, 02:09:18 AM »
This is the Nginx configuration of my domain, where should I modify it?

Contents of File: /etc/nginx/conf.d/vhosts/example.com.conf

server {
   listen 192.168.0.1:80;   
   server_name example.com  www.example.com;

   access_log /usr/local/apache/domlogs/example.com.bytes bytes;
   access_log /usr/local/apache/domlogs/example.com.log combined;
   error_log /usr/local/apache/domlogs/example.com.error.log error;

   location / {
      location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|ttf|svg|eot|sh|webp)$ {
         root /home/example/public_html;               
         expires max;
         try_files $uri $uri/ @backend;
      }
      
      error_page 405 = @backend;
      error_page 500 = @custom;
      add_header X-Cache "HIT from Backend";
      add_header X-XSS-Protection "1; mode=block" always;
      add_header X-Content-Type-Options "nosniff" always;
      proxy_pass http://192.168.0.1:8181;
      include proxy.inc;
   }

   location @backend {
      internal;
      proxy_pass http://192.168.0.1:8181;
      include proxy.inc;
   }

   location @custom {
      internal;
      proxy_pass http://192.168.0.1:8181;
      include proxy.inc;
   }

   location ~ .*\.(php|jsp|cgi|pl|py)?$ {
      proxy_pass http://192.168.0.1:8181;
      include proxy.inc;
   }

   location ~ /\.ht    {deny all;}
   location ~ /\.svn/  {deny all;}
   location ~ /\.git/  {deny all;}
   location ~ /\.hg/   {deny all;}
   location ~ /\.bzr/  {deny all;}

   disable_symlinks if_not_owner from=/home/example/public_html;

   location /.well-known/acme-challenge {
      default_type "text/plain";
      alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
   }

   location /.well-known/pki-validation {
      default_type "text/plain";
      alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
   }
}

server {
   listen 192.168.0.1:80;   
   server_name webmail.example.com;

   access_log /usr/local/apache/domlogs/example.com.bytes bytes;
   access_log /usr/local/apache/domlogs/example.com.log combined;
   error_log /usr/local/apache/domlogs/example.com.error.log error;

   location / {
      proxy_pass  http://127.0.0.1:2095;
      include proxy.inc;
   }

   location ~ /\.ht    {deny all;}
   location ~ /\.svn/  {deny all;}
   location ~ /\.git/  {deny all;}
   location ~ /\.hg/   {deny all;}
   location ~ /\.bzr/  {deny all;}

   disable_symlinks if_not_owner from=/home/example/public_html;

   location /.well-known/acme-challenge {
      default_type "text/plain";
      alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
   }

   location /.well-known/pki-validation {
      default_type "text/plain";
      alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
   }
}

server {
   listen 192.168.0.1:80;   
   server_name mail.example.com;

   access_log /usr/local/apache/domlogs/example.com.bytes bytes;
   access_log /usr/local/apache/domlogs/example.com.log combined;
   error_log /usr/local/apache/domlogs/example.com.error.log error;

   location / {
      proxy_pass  http://127.0.0.1:2095;
      include proxy.inc;
   }

   location ~ /\.ht    {deny all;}
   location ~ /\.svn/  {deny all;}
   location ~ /\.git/  {deny all;}
   location ~ /\.hg/   {deny all;}
   location ~ /\.bzr/  {deny all;}

   disable_symlinks if_not_owner from=/home/example/public_html;

   location /.well-known/acme-challenge {
      default_type "text/plain";
      alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
   }

   location /.well-known/pki-validation {
      default_type "text/plain";
      alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
   }
}

server {
   listen 192.168.0.1:80;   
   server_name cpanel.example.com;

   access_log /usr/local/apache/domlogs/example.com.bytes bytes;
   access_log /usr/local/apache/domlogs/example.com.log combined;
   error_log /usr/local/apache/domlogs/example.com.error.log error;

   location / {
      proxy_pass  https://127.0.0.1:2083;
      include proxy.inc;
   }

   location /pma {
      proxy_pass  https://127.0.0.1:2031;
      include proxy.inc;
   }

   location /roundcube {
      proxy_pass  https://127.0.0.1:2031;
      include proxy.inc;
   }

   location ~ /\.ht    {deny all;}
   location ~ /\.svn/  {deny all;}
   location ~ /\.git/  {deny all;}
   location ~ /\.hg/   {deny all;}
   location ~ /\.bzr/  {deny all;}

   disable_symlinks if_not_owner from=/home/example/public_html;

   location /.well-known/acme-challenge {
      default_type "text/plain";
      alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
   }

   location /.well-known/pki-validation {
      default_type "text/plain";
      alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
   }
}

Offline
****
Re: Nginx configure
« Reply #5 on: June 26, 2022, 04:08:49 AM »
see if the following corrects the issue:

 location / {
      location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|ttf|svg|eot|sh|webp)$ {
         default_type "text/html";
         root /home/example/public_html;               
         expires max;
         try_files $uri $uri/ @backend;
      }
Google Hangouts:  rcschaff82@gmail.com

Offline
*
Re: Nginx configure
« Reply #6 on: June 28, 2022, 07:26:52 AM »
I change it in /etc/nginx/conf.d/vhosts/mydomain.com.conf

Then restart Apache and Nginx, but the URL without the / suffix still displays the source code