Welcome Guest, Not a member yet? Register   Sign In
Tutorial problem with NGINX...?
#1

I just downloaded the latest version of CodeIgniter(3.1.8). I'm using MAMP with Nginx and PHP 7.1.12.

I have successfully accessed the "Welcome to CodeIgniter" view at http://localhost:7888/codeigniter3/ (or localhost:7888/codeigniter3/index.php)

However, when I try to see the newly created page in the tutorial at http://localhost:7888/codeigniter3/index...es/view(or index.php/pages/view) I get

404 Not Found

nginx/1.13.2

Any help would be greatly appreciated.
Reply
#2

In the Nginx Error Log I'm getting the following:
[error] 25962#0: *29 open() "/Applications/MAMP/htdocs/codeigniter3/index.php/pages/view" failed (20: Not a directory), client: 127.0.0.1, server: , request: "GET /codeigniter3/index.php/pages/view HTTP/1.1", host: "localhost:7888".

I'm thinking there's a file in MAMP or Nginx that needs to be adjusted but I can't figure out what it is...Please help!
Reply
#3

I cannot answer your Private Message because you have it turned off.

But here is a link to the tutorial that I built that works.

CodeIgniter News Tutorial Working
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

This works for me in Nginx. Maybe you can find a hint here.

httpd.conf
Code:
user nobody;
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
   worker_connections  1024;
}


http {
    server_names_hash_bucket_size 128;
    server_names_hash_max_size 1024;
    
    ssl_session_cache   shared:SSL:10m;
   ssl_session_timeout 10m;
    
   include       mime.types;
   default_type  application/octet-stream;
    index index.php index.html index.htm;

   #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 off;
    
    server_tokens off;

    # copies data between one FD and other from within the kernel
    # faster then read() + write()
    sendfile on;

    # send headers in one peace, its better then sending them one by one
    #tcp_nopush on;

    # don't buffer data sent, good for small data bursts in real time
    #tcp_nodelay on;
    
    client_body_timeout 10s;
    client_header_timeout 10s;
    keepalive_timeout 10s 10s;
    send_timeout 15s;
    
    client_max_body_size 8M;

    # Gzip Settings
   gzip  on;
    gzip_disable "msie6";
    
    gzip_vary on;
    gzip_comp_level 6;
    gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon image/webp application/json application/vnd.ms-access application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
    
    etag off;
    
   server {
       listen       80;
       server_name  _;
        
        include restrictions.conf;

       location / {
           root   /var/www/sites/emptyDomain;
           index  index.html index.htm;
       }
   }
    
    include /usr/local/nginx/conf/sites-enabled/*.conf;
}


conf/sites-available/localhost.conf
Code:
server {
   listen 80;
   server_name localhost;
    root /var/www/sites/localhost/www;
    #access_log off;
    
    include restrictions.conf;
    include general.conf;
    
    access_log /var/www/logs/localhost_access.log combined;
    error_log /var/www/logs/localhost_error.log;
    
    location / {
        include security.conf;
        # This is cool because no php is touched for static content.
        # include the "?$args" part so non-default permalinks doesn't break when using query string
        try_files $uri $uri/ /index.php?$args;
    }
    
    location ~ \.php$ {
        #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        fastcgi_param HTTP_PROXY "";
        fastcgi_pass unix:/var/run/php-fpm/www.socket;
        include fastcgi.conf;
    }

   error_page  500 502 503 504  /50x.html;
   location = /50x.html {
       root  /usr/share/nginx/html;
   }
}
restrictions.conf
Code:
# Global restrictions configuration file.
# Designed to be included in any server {} block.
location = /favicon.ico {
    log_not_found off;
    access_log off;
}

location = /apple-touch-icon.png {
    log_not_found off;
    access_log off;
}

location = /apple-touch-icon-precomposed.png {
    log_not_found off;
    access_log off;
}

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~ /\. {
    deny all;
}

# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
}
general.conf
Code:
location ~* .(jpg|jpeg|gif|css|png|js|ico|txt|woff|otf|ttf|eot|svg)$ {
    access_log off;
    log_not_found off;
    expires 30d;
   add_header Pragma public;
   add_header Cache-Control "public";
   add_header Vary "Accept-Encoding";
}
security.conf
Code:
## Only allow these request methods ##
    if ($request_method !~ ^(GET|HEAD|POST)$ ) {
        return 444;
    }
## Do not accept DELETE, SEARCH and other methods ##
fastcgi.conf
Code:
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
Reply
#5

Thanks InsiteFX...I turned on my ability to receive private messages.

OK--it gets more interesting. I placed the file "ci3news" that downloaded from your link in my MAMP htdocs folder and then inside my "htdocs/CodeIgniter3" folder(I've now changed this folder name to "htdocs/beta" to simplify). Wherever I place it I get:
403 Forbidden
nginx/1.13.2
Also of note, when I go to "htdocs/beta/user guide" I can access that just fine. But, the following paths all throw "403 Forbidden": "htdocs/ci3news" "htdocs/beta/ci3news" "htdocs/beta/user_guide/ci3news". In addition...if i try to just access all my folders by putting the path localhost:7888/ I also get the "403 Forbidden"
Reply
#6

localhost is usually port 80 or 8080

Make sure you also change the base url in the config file.

I'am on a Windows 10 Pro x64 system

It could be a setting in your nginx
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

Yes--it is a setting in Nginx for sure. The problem seems to be that Nginx doesn't like any url path that ends with anything that doesn't contain an index.php or index.html file.

Any suggestions?
Reply
#8

We need to see your configuration to make suggestions. I posted my configuration on a working NGINX setup.
Reply
#9

@Jreklund: One of the reasons I'm wondering where you got those code snippets is because at http://wiki.nginx.org/Pitfalls it says to NEVER use "if" statements in the nginx configuration file.

I've also tried to incorporate the code into the nginx.config file with no success. I'm wondering if you had to make any adjustments to the Ci config file as well...

~Ryan
Reply
#10

Some are taking from tutorials/documentations and some I have adapted myself. Like disabling logging of images, favicon etc.

Taken from that documentation "If Is Evil": There are cases where you simply cannot avoid using an if, for example, if you need to test a variable which has no equivalent directive.
PHP Code:
if ($request_method POST ) {
 
 return 405;


I'm not using DELETE, PUT, SEARCH etc so if someone sends that I just drop it.

https://nginx.org/en/docs/
https://www.nginx.com/resources/wiki/sta...s/phpfcgi/
https://www.nginx.com/resources/wiki/sta...wordpress/

Try if this one works for you, as it's their default recommendations. And later on add modifications.
https://www.nginx.com/resources/wiki/sta...deigniter/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB