NGINX Configuration...

I have created a project in Lavarel and I’m using nginx as the server the issue I have is that I can’t configure it to work the configuration file I have from my Debian server is:

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 80 default_server;
    listen ::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen ::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html/public;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php?$query_string;
    }

    # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    #
    #    # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    #    # With php-cgi (or other tcp sockets):
    #    fastcgi_pass 127.0.0.1:9000;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#    listen 80;
#    listen ::]:80;
#
#    server_name example.com;
#
#    root /var/www/example.com;
#    index index.html;
#
#    location / {
#        try_files $uri $uri/ =404;
#    }
#}

And in openSUSE Tumbleweed is:


#user  nginx;
worker_processes  1;

# load_module lib64/nginx/modules/ngx_http_fancyindex_module.so;
# load_module lib64/nginx/modules/ngx_http_geoip_module.so;
# load_module lib64/nginx/modules/ngx_http_headers_more_filter_module.so;
# load_module lib64/nginx/modules/ngx_http_image_filter_module.so;
# load_module lib64/nginx/modules/ngx_http_perl_module.so;
# load_module lib64/nginx/modules/ngx_http_xslt_filter_module.so;
# load_module lib64/nginx/modules/ngx_mail_module.so;
# load_module lib64/nginx/modules/ngx_rtmp_module.so;
# load_module lib64/nginx/modules/ngx_stream_geoip_module.so;
# load_module lib64/nginx/modules/ngx_stream_module.so;

#error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

#pid        /run/nginx.pid;


events {
    worker_connections  1024;
    use epoll;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  0;
    keepalive_timeout  65;

    #gzip  on;

    include conf.d/*.conf;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

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

        location / {
            root   /srv/www/htdocs/;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

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

        # 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$ {
        #    root           /srv/www/htdocs/;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   /srv/www/htdocs/;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   /srv/www/htdocs/;
    #        index  index.html index.htm;
    #    }
    #}

    include vhosts.d/*.conf;

}

In general,
Whenever I run some other web server than apache, I never point the document root to /srv/htdocs/ because the permissions for that location are set up specifically for an apache website.

You can create another directory in /srv/ for your nginx document root or some other location altogether.
Script based web server apps like nginx can be set up anywhere on the system.

Also,
A quick Internet search returns many hits running nginx and laravel on Ubuntu.
If you’re using one of those guides for setting up on openSUSE, provide your reference so we can compare what is described, but what you’ve posted so far describes setting up nginx only.

HTH,
TSU

BTW -
Like you, my first thought to deploying nginx is to create a configuration file and “just run” it.

But,
Especially if you have ideas about deploying a Production instance with auto-boot,
Or, if you want to “just run” an NGINX for the first time,

It’s probably easiest to just install the nginx package

zypper in nginx

After that,
I’d expect that with the usual help, MAN pages and other documentation that you can easily modify to do whatever you wish.

TSU

Yes, I have NGINX but the openSUSE config doesen’t work with Lavarel.

I need this part:

location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php?$query_string;
    }

For my lavarel script to run but I don’t know how to configure the configuration of NGINX for openSUSE to reflect the configuration from Debian that I posted above.

Let’s start from scratch…
Need to know what guide you’re following to set up on openSUSE, particularly since AFAIK there is no official documentation. My own NGINX use has been pretty basic… supporting my own chosen technologies of HTML5/CSS3/Javascript.

Since it looks like Laravel is a PHP based framework, there is a pretty fair amount of setup you need to do…
The Laravel requirements are described on the following page, but with instructions for deploying on Ubuntu

https://laravel.com/docs/5.6

The most basic NGINX/PHP setup is described in many places, and can be found with an Internet search “LEMP on openSUSE” – Skimming a few of them, with few exceptions they all look like they were originally written by the same person and contain a number of unique procedures… Like creating a special SuSEFW2 rule that combines SSH, HTTP and HTTPS ports, using “rc” commands to manage services and more… then applied to LEAP. None of those oddities are harmful but show their legacy roots.

But, even after following one of those LEMP guides, you’d still have to do a lot of additional installation and configuration to support the additional requirements described in the Laravel documentation.

Some alternatives seem to exist that can provide a ready-to-go setup…
The referenced Laravel documentation describes building a “Homestead” virtual machine (again, on Ubuntu).
There are a great many Dockerhub containers built by companies and individuals, some with added features you may want for your own purposes.

If you want to try to continue to build a “native” NGINX/Laravel install,
We can continue on, but you’ll have to describe what you’ve done to this point… and in detail so that what you’ve done can be replicated.

Otherwise,
If you’re more interested in practicality and are familiar with the Ubuntu/Debian ecosystem, then I’d recommend the other options I’ve described.

TSU

The lavarel project is 100% complete I need to figure out how I can use “mod_rewrite (like apache)” on nginx because all my custom files from the site are in the /public directory.

This code does the trick on Debian:


location / {         # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php?$query_string;
    }

But no luck with openSUSE and also I use php-fpm:

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    #
    #    # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    #    # With php-cgi (or other tcp sockets):
    #    fastcgi_pass 127.0.0.1:9000;
    }

Without seeing what your website directory looks like fully…

If you want to create NGINX rules that re-write the directory URLs…
https://www.nginx.com/blog/creating-nginx-rewrite-rules/
https://www.nginx.com/blog/converting-apache-to-nginx-rewrite-rules/

But if you don’t actually need to re-write the URLs but only need to tell NGINX where your website files are, then maybe a simple modification of your Debian configuration is what you need, eg the following

location / {         # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ $uri/public /index.php?$query_string;
    }

TSU