Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a nginx tutorial #145

Closed
Benjamin-Loison opened this issue Mar 18, 2023 · 20 comments
Closed

Add a nginx tutorial #145

Benjamin-Loison opened this issue Mar 18, 2023 · 20 comments
Assignees
Labels
enhancement New feature or request low priority Nice to have feature. quick A task that should take less than two hours to complete.

Comments

@Benjamin-Loison Benjamin-Loison added enhancement New feature or request high priority Issue disabling the user to use correctly the main features. medium A task that should take less than a day to complete. labels Mar 18, 2023
@anshtyagi0
Copy link

This will help a lot

@Benjamin-Loison Benjamin-Loison self-assigned this Mar 18, 2023
@Benjamin-Loison
Copy link
Owner Author

@anshtyagi0 Let me know if this tutorial fits your needs.

@Benjamin-Loison Benjamin-Loison added the waiting details Further information is requested label Mar 18, 2023
@anshtyagi0
Copy link

nah this is not working

@anshtyagi0
Copy link

It says bad gatway

@Benjamin-Loison
Copy link
Owner Author

@anshtyagi0
Please send the content of /var/log/nginx/error.log to see if there is a reason for this to happen.

@anshtyagi0
Copy link

2023/03/19 06:08:15 [error] 58136#58136: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 103.55.89.42, server: youtubeapi.fluiddev.xyz, request: "GET / HTTP/1.1", upstrea>
2023/03/19 06:08:17 [error] 58136#58136: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 103.55.89.42, server: youtubeapi.fluiddev.xyz, request: "GET / HTTP/1.1", upstrea>
2023/03/19 06:08:20 [error] 58136#58136: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 103.55.89.42, server: youtubeapi.fluiddev.xyz, request: "GET /videos HTTP/1.1", u>
2023/03/19 06:08:22 [error] 58136#58136: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 103.55.89.42, server: youtubeapi.fluiddev.xyz, request: "GET /videos HTTP/1.1", u>
2023/03/19 06:08:23 [error] 58136#58136: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 103.55.89.42, server: youtubeapi.fluiddev.xyz, request: "GET / HTTP/1.1", upstrea>
2023/03/19 06:08:25 [error] 58136#58136: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 103.55.89.42, server: youtubeapi.fluiddev.xyz, request: "GET /noKey/ HTTP/1.1", u>
2023/03/19 06:17:11 [error] 58136#58136: *21 connect() failed (111: Connection refused) while connecting to upstream, client: 35.195.241.126, server: youtubeapi.fluiddev.xyz, request: "GET / HTTP/1.1", upst>
2023/03/19 07:13:25 [error] 58136#58136: *26 connect() failed (111: Connection refused) while connecting to upstream, client: 193.32.162.159, server: youtubeapi.fluiddev.xyz, request: "GET / HTTP/1.1", upst>
2023/03/19 07:35:23 [error] 58136#58136: *28 connect() failed (111: Connection refused) while connecting to upstream, client: 162.243.136.9, server: youtubeapi.fluiddev.xyz, request: "GET / HTTP/1.1", upstr>
2023/03/19 08:05:39 [error] 58136#58136: *33 connect() failed (111: Connection refused) while connecting to upstream, client: 94.102.51.9, server: youtubeapi.fluiddev.xyz, request: "GET / HTTP/1.0", upstrea>
2023/03/19 08:05:42 [error] 58136#58136: *35 connect() failed (111: Connection refused) while connecting to upstream, client: 94.102.51.9, server: youtubeapi.fluiddev.xyz, request: "GET / HTTP/1.0", upstrea>
2023/03/19 08:13:45 [error] 58136#58136: *37 connect() failed (111: Connection refused) while connecting to upstream, client: 151.246.125.55, server: youtubeapi.fluiddev.xyz, request: "GET / HTTP/1.1", upst>
2023/03/19 08:16:13 [error] 58136#58136: *39 connect() failed (111: Connection refused) while connecting to upstream, client: 193.32.162.159, server: youtubeapi.fluiddev.xyz, request: "GET / HTTP/1.1", upst>
2023/03/19 08:26:10 [error] 58136#58136: *41 connect() failed (111: Connection refused) while connecting to upstream, client: 103.55.89.42, server: youtubeapi.fluiddev.xyz, request: "GET / HTTP/1.1", upstre>

@Benjamin-Loison
Copy link
Owner Author

@anshtyagi0
Can you give me the result of tree /var/www/html/ and the content of /etc/nginx/sites-available/default?

@anshtyagi0
Copy link

anshtyagi0 commented Mar 19, 2023

Screenshot 2023-03-19 at 3 22 53 PM

       server {
            listen 127.0.0.1:9000;

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

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

        server_name youtubeapi.fluiddev.xyz;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # proxy_pass http://localhost:8080;
                # proxy_http_version 1.1;
                # proxy_set_header Upgrade $http_upgrade;
                # proxy_set_header Connection 'upgrade';
                # proxy_set_header Host $host;
                # proxy_cache_bypass $http_upgrade;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
               include snippets/fastcgi-php.conf;

        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;

        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #}

        # deny access to .htaccess files, if Apache's document root
        location = /YouTube-operational-API/liveChats {
                rewrite ^(.*)$ /YouTube-operational-API/liveChats.php;
        }

        location = /YouTube-operational-API/lives {
                rewrite ^(.*)$ /YouTube-operational-API/lives.php;
        }

        location = /YouTube-operational-API/commentThreads {
                rewrite ^(.*)$ /YouTube-operational-API/commentThreads.php;
        }

        location = /YouTube-operational-API/webhooks {
                rewrite ^(.*)$ /YouTube-operational-API/webhooks.php;
        }

        location = /YouTube-operational-API/community {
                rewrite ^(.*)$ /YouTube-operational-API/community.php;
        }

        location = /YouTube-operational-API/channels {
                rewrite ^(.*)$ /YouTube-operational-API/channels.php;
        }

        location = /YouTube-operational-API/playlistItems {
                rewrite ^(.*)$ /YouTube-operational-API/playlistItems.php;
        }

        location = /YouTube-operational-API/playlists {
                rewrite ^(.*)$ /YouTube-operational-API/playlists.php;
        }

        location = /YouTube-operational-API/videos {
                rewrite ^(.*)$ /YouTube-operational-API/videos.php;
        }

        location = /YouTube-operational-API/search {
                rewrite ^(.*)$ /YouTube-operational-API/search.php;
        }

        location = /YouTube-operational-API/ytPrivate/keys.txt {
                deny all;
        }

        # 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.php index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

@anshtyagi0
Copy link

anshtyagi0 commented Mar 19, 2023

@Benjamin-Loison got bit messy but can't help with that it is taking it as markdown

@anshtyagi0
Copy link

now it is not even logging any error just showing 404 not found

@Benjamin-Loison
Copy link
Owner Author

Benjamin-Loison commented Mar 19, 2023

@anshtyagi0
Maybe returning me the result of ls -lah /var/www/html/YouTube-operational-API/ may help verify permissions.

@anshtyagi0
Copy link

Screenshot 2023-03-19 at 3 31 42 PM

@Benjamin-Loison

@anshtyagi0
Copy link

Screenshot 2023-03-19 at 3 32 55 PM

Got this error while reloading server. @Benjamin-Loison

@anshtyagi0
Copy link

Screenshot 2023-03-19 at 3 39 16 PM

@Benjamin-Loison
Copy link
Owner Author

Benjamin-Loison commented Mar 19, 2023

@anshtyagi0
I have similar permissions on my end.
I fixed your markdown rendering by the way.

It seems that PHP activation wasn't correct on your end:

        #location ~ \.php$ {
               include snippets/fastcgi-php.conf;

        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;

        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #}

Should be:

        location ~ \.php$ {
               include snippets/fastcgi-php.conf;

        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;

               fastcgi_pass unix:/run/php/php-fpm.sock;
        }

Here is the wanted nginx site configuration:

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

	# 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/ =404;
	}

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

 	location = /YouTube-operational-API/liveChats {
		rewrite ^(.*)$ /YouTube-operational-API/liveChats.php;
	}

 	location = /YouTube-operational-API/lives {
		rewrite ^(.*)$ /YouTube-operational-API/lives.php;
	}

 	location = /YouTube-operational-API/commentThreads {
		rewrite ^(.*)$ /YouTube-operational-API/commentThreads.php;
	}

 	location = /YouTube-operational-API/webhooks {
		rewrite ^(.*)$ /YouTube-operational-API/webhooks.php;
	}

 	location = /YouTube-operational-API/community {
		rewrite ^(.*)$ /YouTube-operational-API/community.php;
	}

 	location = /YouTube-operational-API/channels {
		rewrite ^(.*)$ /YouTube-operational-API/channels.php;
	}

 	location = /YouTube-operational-API/playlistItems {
		rewrite ^(.*)$ /YouTube-operational-API/playlistItems.php;
	}

 	location = /YouTube-operational-API/playlists {
		rewrite ^(.*)$ /YouTube-operational-API/playlists.php;
	}

 	location = /YouTube-operational-API/videos {
		rewrite ^(.*)$ /YouTube-operational-API/videos.php;
	}

 	location = /YouTube-operational-API/search {
		rewrite ^(.*)$ /YouTube-operational-API/search.php;
	}

 	location = /YouTube-operational-API/ytPrivate/keys.txt {
		deny all;
	}

	# 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.php index.html;
#
#	location / {
#		try_files $uri $uri/ =404;
#	}
#}

To be honest my tutorial was tested under Linux Mint, not Ubuntu, I added this remark as a possibility of improvement for the nginx tutorial.

@Benjamin-Loison
Copy link
Owner Author

Benjamin-Loison commented Mar 19, 2023

Not relevant here but prefer text over images, cf this Stack Overflow question.

@anshtyagi0
Copy link

ok

@anshtyagi0
Copy link

Ok thanks fixed it is working now.

@Benjamin-Loison
Copy link
Owner Author

Thanks for the feedback, I close this issue then, sorry for the not yet perfect tutorial.

@Benjamin-Loison Benjamin-Loison removed their assignment May 11, 2023
@Benjamin-Loison Benjamin-Loison added low priority Nice to have feature. and removed waiting details Further information is requested high priority Issue disabling the user to use correctly the main features. medium A task that should take less than a day to complete. labels May 11, 2023
@Benjamin-Loison Benjamin-Loison added the quick A task that should take less than two hours to complete. label May 11, 2023
@Benjamin-Loison
Copy link
Owner Author

Make the tutorial able to also work securely for the no-key endpoint (cf yt4.lemnoslife.com).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low priority Nice to have feature. quick A task that should take less than two hours to complete.
Projects
None yet
Development

No branches or pull requests

2 participants