<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by DHANESH PARAYANMARATH on Medium]]></title>
        <description><![CDATA[Stories by DHANESH PARAYANMARATH on Medium]]></description>
        <link>https://medium.com/@dpon1996?source=rss-bef3dc3f5af6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4Ulu48BCaQJvVDTsAs05OA.jpeg</url>
            <title>Stories by DHANESH PARAYANMARATH on Medium</title>
            <link>https://medium.com/@dpon1996?source=rss-bef3dc3f5af6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 12:48:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dpon1996/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Embedding Instagram Reels in a Flutter App: The Real Fix]]></title>
            <link>https://medium.com/@dpon1996/embedding-instagram-reels-in-a-flutter-app-the-real-fix-ce924ec5c8a3?source=rss-bef3dc3f5af6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce924ec5c8a3</guid>
            <category><![CDATA[instagram-api]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[instagra]]></category>
            <dc:creator><![CDATA[DHANESH PARAYANMARATH]]></dc:creator>
            <pubDate>Tue, 24 Jun 2025 15:08:49 GMT</pubDate>
            <atom:updated>2025-06-24T15:08:49.491Z</atom:updated>
            <content:encoded><![CDATA[<p>When building a Flutter app that displays Instagram content, the first idea that comes to mind is to use Instagram’s official <strong>embed code</strong> — the one that includes a &lt;blockquote&gt; and a &lt;script src=&quot;//www.instagram.com/embed.js&quot;&gt;. This is what Instagram provides for web integration, and it works great... on websites.</p><p>But in Flutter? Not so much.</p><h3>The Problem</h3><p>Flutter’s WebView is a native component. It behaves like a mini sandboxed browser instance and <strong>doesn&#39;t support running </strong><strong>&lt;script&gt; tags</strong> or rendering external JavaScript-heavy components the same way a full browser does. When I tried to directly embed the Instagram post using the official HTML embed code, it simply didn’t render the post. The script did not execute, and I was left with a blank or static frame.</p><p>This was a blocker — because my goal was to <strong>play an Instagram Reel directly inside the app</strong>, not open it externally.</p><h3>What I Actually Needed</h3><p>After breaking the problem down, I realized I didn’t need the full embed system with comments, profile overlays, or other JS-based elements. I just needed:</p><ul><li>A <strong>working Instagram Reel player</strong></li><li>Inside a Flutter app</li><li>That supports <strong>tap and fullscreen playback</strong></li><li>Without relying on external script injection</li></ul><h3>The Solution: Using Instagram’s Embed-Friendly Iframe</h3><p>Instagram provides an <strong>embed version of every post/reel</strong> that works inside an &lt;iframe&gt;:</p><pre>https://www.instagram.com/reel/&lt;REEL_ID&gt;/embed</pre><p>This URL points to a simple page Instagram hosts, designed to be embedded. It doesn’t rely on external script injection — it’s a standalone mini page that just works inside iframes. It also supports <strong>mobile playback, tap-to-fullscreen</strong>, and basic controls.</p><p>To load this in Flutter, I couldn’t use a regular HTTP initialUrl either, because I wanted this to be entirely dynamic and self-contained. The best method was to:</p><ol><li>Create a minimal HTML page with just an &lt;iframe&gt; pointing to the Instagram embed.</li><li>Encode that HTML to base64.</li><li>Load it into a WebView as a data:text/html;base64,... URI.</li></ol><h3>Key Code Snippet</h3><p>Here’s the core concept that makes it all work:</p><pre>final htmlContent = &#39;&#39;&#39;<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;body style=&quot;margin:0;&quot;&gt;<br>    &lt;iframe src=&quot;https://www.instagram.com/reel/$reelId/embed&quot;<br>            width=&quot;100%&quot; height=&quot;100%&quot; frameborder=&quot;0&quot;<br>            scrolling=&quot;no&quot; allowfullscreen&gt;<br>    &lt;/iframe&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;<br>&#39;&#39;&#39;;<br><br>final encodedHtml = base64Encode(const Utf8Encoder().convert(htmlContent));<br><br>WebView(<br>  initialUrl: &#39;data:text/html;base64,$encodedHtml&#39;,<br>  javascriptMode: JavascriptMode.unrestricted,<br>);</pre><p>That’s it. No dependency on Instagram scripts. No need for external hosting. And no reliance on oEmbed or Graph API just to show a video.</p><h3>Result</h3><p>The WebView cleanly loads the Instagram embed page. When tapped, the video goes full screen, just like in the official Instagram app. Since the player is controlled by Instagram&#39;s internal logic, it handles orientation, fullscreen toggling, and playback behavior automatically.</p><h3>Why Other Methods Didn’t Work</h3><ul><li>The &lt;blockquote&gt;+&lt;script&gt; embed fails silently in Flutter&#39;s WebView.</li><li>Instagram doesn’t expose a direct video URL, so custom players aren’t an option.</li><li>Embedding inside a non-iframe HTML page doesn’t render because script execution is blocked or isolated.</li></ul><h3>When to Use This</h3><p>Use this approach if:</p><ul><li>You want to show <strong>Instagram Reels</strong> or <strong>posts</strong> in a Flutter app.</li><li>You want a <strong>native-feeling playback experience</strong>.</li><li>You don’t want to depend on Graph API or worry about access tokens.</li></ul><h3>Final Thoughts</h3><p>This small but important workaround allowed me to embed real Instagram content inside my Flutter app — without jumping through unnecessary authentication or rendering hoops. If you’ve been struggling with Instagram’s script-based embed approach inside a WebView, this is the cleanest, most direct solution.</p><p>Just use their own embed URL with an iframe. No script tags. No headaches.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce924ec5c8a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Minimal “Read More / Show Less” Text in Flutter]]></title>
            <link>https://medium.com/@dpon1996/building-a-minimal-read-more-show-less-text-in-flutter-792416475178?source=rss-bef3dc3f5af6------2</link>
            <guid isPermaLink="false">https://medium.com/p/792416475178</guid>
            <category><![CDATA[read-more]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[DHANESH PARAYANMARATH]]></dc:creator>
            <pubDate>Fri, 20 Jun 2025 09:14:26 GMT</pubDate>
            <atom:updated>2025-06-20T09:16:21.314Z</atom:updated>
            <content:encoded><![CDATA[<h3>Say More with Less: Flutter Read More Text UI</h3><p>Sometimes a long block of text just doesn’t look great on a compact UI — especially when you’re trying to show a preview or a short description.</p><p>We want to build a <strong>Flutter widget</strong> that behaves like a classic “Read More / Show Less” feature, but with a clean and minimal approach — <strong>no external packages required</strong>.</p><h3>Key Objectives</h3><ul><li>Show only <strong>2 lines</strong> of text by default</li><li>Show full text when the user taps a toggle (expand/collapse)</li><li><strong>Automatically detect</strong> if the text exceeds 2 lines and show the expand icon only in that case</li><li>Entirely built using <strong>Flutter’s built-in tools</strong> (like TextPainter, TextOverflow, StatefulWidget, etc.)</li></ul><p>This solution gives us full control over layout behavior while keeping the widget lightweight and easy to maintain.</p><h3>The Core Idea</h3><h3>The Core Idea</h3><p>The heart of this feature lies in one simple question:</p><p><strong><em>“How do we know if a text spans more than two lines before rendering it?”</em></strong></p><p>Flutter’s built-in Text widget doesn&#39;t directly give us this information. That’s where <strong>TextPainter</strong> comes in — a powerful, low-level utility that allows us to measure and layout text manually, just like Flutter does internally during rendering.</p><h3>Here’s the breakdown:</h3><p><strong>Step 1: Create a </strong><strong>TextSpan</strong></p><ul><li>A TextSpan holds the raw text and its styling (like font size, weight, line height).</li></ul><p><strong>Step 2: Use </strong><strong>TextPainter to measure the text</strong></p><ul><li>TextPainter lets us simulate how Flutter will layout the text, without actually rendering it on screen. We can tell it:</li><li>What text to measure (text)</li><li>How many lines to constrain (maxLines)</li><li>The direction of the text (textDirection)</li><li>Then we call .layout(maxWidth: ...) to simulate how the text fits in the available space.</li></ul><p><strong>Step 3: Ask if it overflows</strong></p><ul><li>After laying out the text, we check:</li></ul><pre>textPainter.didExceedMaxLines</pre><ul><li>If this returns true, the text is too long and <strong>spills over the max lines (in our case, 2 lines).</strong> That’s our signal to show the expand/collapse button.</li></ul><h3>Final Logic:</h3><ul><li>When the widget initializes, we check the line count once the layout is ready.</li><li>If the text fits within 2 lines → no button is shown.</li><li>If it overflows → we show an expand icon, allowing the user to view the full content.</li></ul><p>This gives us a <strong>fully native</strong> way to build a smart “read more” feature, with zero dependencies, full control, and adaptive UI behavior.</p><h3>Reusable ReadMoreText Widget</h3><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class ReadMoreText extends StatefulWidget {<br>  final String text;<br>  final TextStyle? style;<br>  final int maxLines;<br><br>  const ReadMoreText({<br>    super.key,<br>    required this.text,<br>    this.style,<br>    this.maxLines = 2,<br>  });<br><br>  @override<br>  State&lt;ReadMoreText&gt; createState() =&gt; _ReadMoreTextState();<br>}<br><br>class _ReadMoreTextState extends State&lt;ReadMoreText&gt; {<br>  bool isExpanded = false;<br>  bool showToggle = false;<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    WidgetsBinding.instance.addPostFrameCallback((_) =&gt; _checkOverflow());<br>  }<br><br>  void _checkOverflow() {<br>    final span = TextSpan(text: widget.text, style: widget.style);<br><br>    final tp = TextPainter(<br>      text: span,<br>      maxLines: widget.maxLines,<br>      textDirection: TextDirection.ltr,<br>    );<br><br>    final maxWidth = context.size?.width ?? MediaQuery.of(context).size.width;<br>    tp.layout(maxWidth: maxWidth);<br><br>    if (tp.didExceedMaxLines) {<br>      setState(() {<br>        showToggle = true;<br>      });<br>    }<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Row(crossAxisAlignment: CrossAxisAlignment.start, children: [<br>      Expanded(<br>        child: Text(<br>          widget.text,<br>          style: widget.style,<br>          maxLines: isExpanded ? null : widget.maxLines,<br>          overflow: isExpanded ? TextOverflow.visible : TextOverflow.ellipsis,<br>        ),<br>      ),<br>      if (showToggle)<br>        IconButton(<br>          icon: Icon(isExpanded ? Icons.expand_less : Icons.expand_more),<br>          onPressed: () =&gt; setState(() =&gt; isExpanded = !isExpanded),<br>          visualDensity: VisualDensity.compact,<br>        ),<br>    ]);<br>  }<br>}</pre><h4>How to Use It</h4><pre>ReadMoreText(<br>  text: &quot;Your long description goes here...&quot;,<br>  style: TextStyle(fontSize: 14, height: 1.5),<br>)</pre><h3>Conclusion</h3><p>With a few lines of code, you can implement a user-friendly text preview system that adapts based on the content. It keeps your UI clean without sacrificing access to full information.</p><p>If you’re designing cards, lists, or summaries — this pattern is a must-have!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=792416475178" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Dive into Flutter Quick Actions: App Launcher Shortcuts]]></title>
            <link>https://medium.com/@dpon1996/deep-dive-into-flutter-quick-actions-app-launcher-shortcuts-a7a97b8e00cd?source=rss-bef3dc3f5af6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7a97b8e00cd</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[quick-action]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[DHANESH PARAYANMARATH]]></dc:creator>
            <pubDate>Wed, 29 Jan 2025 11:08:29 GMT</pubDate>
            <atom:updated>2025-01-29T11:08:29.415Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction</h4><p>Flutter apps can provide users with a seamless experience by leveraging <strong>Quick Actions</strong> — a feature that allows users to access specific app functionalities directly from the app launcher by long-pressing the app icon. This is particularly useful for improving accessibility and streamlining user workflows.</p><p>In this blog, we’ll explore how <strong>Quick Actions</strong> work, how to implement them using the quick_actions package, and how they function internally across different platforms.</p><h3>Understanding Quick Actions in Flutter</h3><h4>How Do Quick Actions Work?</h4><p>Quick Actions are <strong>static</strong> or <strong>dynamic</strong> shortcuts that are registered within the app and exposed to the OS. When the user long-presses the app icon, these shortcuts appear as options, allowing the user to jump directly into specific app features.</p><h4>Platform Differences</h4><ul><li><strong>Android:</strong> Uses the ShortcutManager API to manage static and dynamic shortcuts.</li><li><strong>iOS:</strong> Uses UIApplicationShortcutItem to define shortcuts in the Info.plist file.</li></ul><p>Flutter’s quick_actions package provides a unified API to handle these shortcuts seamlessly across both platforms.</p><h3>Setting Up Quick Actions in Flutter</h3><h4>1. Install the Package</h4><p>Add quick_actions to your pubspec.yaml:</p><pre>dependencies:<br>  flutter:<br>    sdk: flutter<br>  quick_actions: &lt;latest_version&gt;</pre><p>Run:</p><pre>dart pub get</pre><h3>2. Define Shortcut Items</h3><p>In your app’s main.dart:</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:quick_actions/quick_actions.dart&#39;;<br><br>void main() {<br>  runApp(MyApp());<br>}<br>class MyApp extends StatefulWidget {<br>  @override<br>  _MyAppState createState() =&gt; _MyAppState();<br>}<br>class _MyAppState extends State&lt;MyApp&gt; {<br>  final QuickActions quickActions = QuickActions();<br>  String _actionMessage = &quot;No action selected&quot;;<br>  @override<br>  void initState() {<br>    super.initState();<br>    quickActions.setShortcutItems([<br>      ShortcutItem(type: &#39;action_home&#39;, localizedTitle: &#39;Home&#39;, icon: &#39;home&#39;),<br>      ShortcutItem(type: &#39;action_profile&#39;, localizedTitle: &#39;Profile&#39;, icon: &#39;profile&#39;),<br>      ShortcutItem(type: &#39;action_settings&#39;, localizedTitle: &#39;Settings&#39;, icon: &#39;settings&#39;),<br>    ]);<br>    <br>    quickActions.initialize((String shortcutType) {<br>      setState(() {<br>        _actionMessage = &quot;Selected: $shortcutType&quot;;<br>      });<br>    });<br>  }<br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      home: Scaffold(<br>        appBar: AppBar(title: Text(&quot;Quick Actions Example&quot;)),<br>        body: Center(child: Text(_actionMessage, style: TextStyle(fontSize: 18))),<br>      ),<br>    );<br>  }<br>}</pre><h4>How quick_actions Works Internally</h4><ol><li><strong>Initialization</strong></li></ol><ul><li>The package detects the <strong>platform</strong> and sets up listeners for shortcut actions.</li><li>On <strong>iOS</strong>, it reads the Info.plist file.</li><li>On <strong>Android</strong>, it interacts with the ShortcutManager.</li></ul><p><strong>2. Handling Shortcut Selection</strong></p><ul><li>When a shortcut is selected, the app receives an event via the initialize callback.</li></ul><p><strong>3. Limitations &amp; Best Practices</strong></p><ul><li>iOS only supports <strong>static shortcuts</strong> (defined in Info.plist).</li><li>Android supports both <strong>static and dynamic</strong> shortcuts.</li><li>Limit the number of shortcuts to <strong>4</strong> for optimal user experience.</li><li>Use meaningful icons and titles to enhance usability.</li></ul><h3>Advanced Use Cases</h3><ol><li>Navigating to Specific Screens</li></ol><p>Modify initialize to navigate:</p><pre>quickActions.initialize((String shortcutType) {<br>  if (shortcutType == &#39;action_home&#39;) {<br>    Navigator.push(context, MaterialPageRoute(builder: (_) =&gt; HomeScreen()));<br>  } else if (shortcutType == &#39;action_profile&#39;) {<br>    Navigator.push(context, MaterialPageRoute(builder: (_) =&gt; ProfileScreen()));<br>  }<br>});</pre><p>2. Passing Data from Quick Actions</p><p>You can pass data by encoding it in the type string and parsing it inside initialize.</p><p>3. Handling Deep Linking with Quick Actions</p><p>Combine Quick Actions with deep linking to open specific in-app content.</p><h3>Conclusion</h3><p>Quick Actions provide an easy way to enhance user experience by enabling <strong>fast access</strong> to app features. With quick_actions, you can implement them efficiently with minimal platform-specific code.</p><h3>Key Takeaways</h3><ul><li>Quick Actions allow users to access app features from the launcher.</li><li>quick_actions abstracts platform-specific implementations.</li><li>Android supports both <strong>static and dynamic</strong> shortcuts, whereas iOS primarily supports <strong>static</strong> shortcuts.</li><li>Best practices include limiting shortcuts to <strong>4</strong>, using clear icons, and ensuring navigation logic is well-handled.</li></ul><p>Would you like to see more advanced examples, such as dynamic shortcuts or deep linking integrations? Let me know in the comments! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7a97b8e00cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking Flutter Code Push with Shorebird]]></title>
            <link>https://medium.com/@dpon1996/unlocking-flutter-code-push-with-shorebird-f2aadd96c396?source=rss-bef3dc3f5af6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2aadd96c396</guid>
            <category><![CDATA[code-push]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[shorebirds]]></category>
            <dc:creator><![CDATA[DHANESH PARAYANMARATH]]></dc:creator>
            <pubDate>Mon, 23 Dec 2024 11:53:44 GMT</pubDate>
            <atom:updated>2025-02-05T06:59:30.721Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*x-waOngqPj-7NGBHJyWBLg.png" /></figure><p>Flutter has revolutionized cross-platform app development with its performance and versatility. But even with its powerful capabilities, updating Flutter apps still requires users to download a new version from app stores. Enter <strong>code push</strong>, a game-changing approach to delivering updates seamlessly without app store intervention. In this blog, we’ll explore the basics of Flutter code push and how <strong>Shorebird</strong> supports this feature to enhance app development.</p><h4>What is Code Push?</h4><p>Code push enables developers to update their app’s codebase remotely. Instead of requiring users to download a new version of the app, the updates are pushed directly to the app. This approach allows for:</p><ul><li><strong>Faster fixes:</strong> Bugs can be resolved and deployed instantly.</li><li><strong>Improved user experience:</strong> Updates roll out without requiring users to visit app stores.</li><li><strong>Increased flexibility:</strong> Developers can continuously iterate and enhance their apps.</li></ul><h4>Challenges with Code Push in Flutter</h4><p>Flutter apps bundle the Dart code, assets, and Flutter engine into the app binary. While this approach ensures performance and reliability, it limits traditional code-push mechanisms. The Flutter ecosystem needed a tailored solution that respects platform guidelines and Flutter’s architecture. That’s where Shorebird comes in.</p><h4>Introducing Shorebird</h4><p>Shorebird is a cutting-edge tool that brings code push to Flutter. It is built to work seamlessly with Flutter’s unique requirements, offering a developer-friendly solution to ship updates faster. With Shorebird, you can:</p><ol><li><strong>Push updates directly:</strong> Deliver patches without releasing a new app version.</li><li><strong>Streamline workflows:</strong> Integrate code push into your existing CI/CD pipeline.</li><li><strong>Respect app store policies:</strong> Ensure compliance with guidelines while benefiting from code push.</li></ol><h4>Why Choose Shorebird?</h4><p>Shorebird stands out because it is designed specifically for Flutter apps. It focuses on:</p><ul><li><strong>Ease of integration:</strong> Simple setup and integration with your existing Flutter project.</li><li><strong>Robust support:</strong> A reliable way to ship updates across Android and iOS platforms.</li><li><strong>Community-driven growth:</strong> Backed by a dedicated team and growing Flutter community.</li></ul><h4>How Does Shorebird Work?</h4><p>Shorebird operates by injecting a patch mechanism into the app. When updates are pushed, the app fetches and applies them dynamically. This approach keeps users up-to-date without compromising app performance.</p><p><strong>Patch Creation</strong>:</p><ul><li>When a developer wants to push an update (e.g., a bug fix or a minor feature update), they don’t create a whole new app version. Instead, they create a <strong>patch</strong> or a set of changes that modify the app’s behavior.</li><li>These patches are generally <strong>Dart code</strong> (since Flutter apps are written in Dart) or resources like images, assets, etc.</li></ul><p><strong>Storage and Distribution</strong>:</p><ul><li>The <strong>patches</strong> are stored on a <strong>server</strong> (managed by Shorebird). This is a cloud-based infrastructure that stores the patches and makes them available for download.</li><li><strong>Shorebird</strong> handles all of this for you, so you don’t need to worry about setting up your own server or storage solution.</li></ul><p><strong>App Update Flow</strong>:</p><ul><li><strong>When the app runs</strong>, it checks if there are any updates (patches) available by communicating with the Shorebird server.</li><li>If a patch is available, the app <strong>downloads the patch</strong> dynamically and applies it without restarting the app (depending on the type of patch).</li><li>The patch typically includes only <strong>code changes</strong> (like Dart code) and can even update app assets (like images or fonts), depending on how Shorebird is configured.</li></ul><p>While this blog focuses on introducing the concept, a <strong>detailed implementation guide</strong> for Shorebird Flutter integration is coming soon. Stay tuned to learn how to set up Shorebird in your Flutter projects, configure patching workflows, and test your code push functionality.</p><h4>Conclusion</h4><p>Code push is a valuable addition to Flutter development, and Shorebird makes it accessible and efficient. As apps grow in complexity and user demands rise, tools like Shorebird help developers stay agile and responsive. In the next blog, we’ll dive deep into the technical aspects of setting up Shorebird for your Flutter app.</p><p><strong>Have you tried Shorebird yet?</strong> Let us know your thoughts and experiences in the comments below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2aadd96c396" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling S3 CORS Issues: Why Some Images Fail While Others Work]]></title>
            <link>https://medium.com/@dpon1996/handling-s3-cors-issues-why-some-images-fail-while-others-work-61f976bc41e7?source=rss-bef3dc3f5af6------2</link>
            <guid isPermaLink="false">https://medium.com/p/61f976bc41e7</guid>
            <category><![CDATA[cors]]></category>
            <category><![CDATA[image]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[DHANESH PARAYANMARATH]]></dc:creator>
            <pubDate>Wed, 04 Dec 2024 19:01:51 GMT</pubDate>
            <atom:updated>2024-12-04T19:01:51.184Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GDpDQ924h4gnehOV.png" /></figure><p>Amazon S3 is widely used to store and serve assets like images. However, when combined with CloudFront or accessed via web apps, you might encounter unexpected CORS (Cross-Origin Resource Sharing) issues. Recently, I resolved a specific case where some images failed with CORS errors while others worked perfectly. This blog post details the root causes, findings, and solutions to help others facing similar challenges.</p><h3>The Issue: Some Images Work, Some Don’t</h3><h4>Symptoms:</h4><ul><li>While serving images via S3 and CloudFront for a Flutter web app, most images loaded correctly, but specific images returned the dreaded:</li></ul><pre>No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource.</pre><p>Accessing the problematic images directly via S3 URLs worked fine, but accessing them through the app or CloudFront triggered CORS errors.</p><h4>Why This Happens:</h4><p>The discrepancy arises due to:</p><ol><li><strong>Metadata Variations</strong>: Some S3 objects might have custom metadata or lack headers (like ETag) that the browser or app relies on during CORS requests.</li><li><strong>CORS Policy Updates</strong>: S3 buckets apply a specific CORS configuration. If headers like ETag are not explicitly exposed, browsers block the requests.</li><li><strong>CloudFront Caching</strong>: Older cached versions of S3 objects might lack the proper headers after updates.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*mEcrAZrEToolu9my" /></figure><h3>Why It Worked Earlier</h3><ol><li><strong>Configuration Was Lenient</strong>:</li></ol><ul><li>Early tests likely bypassed strict checks because browsers cached results or requests didn’t demand exposed headers like ETag.</li></ul><p><strong>2. Metadata Updates</strong>:</p><ul><li>Any changes to the S3 bucket or uploaded objects might alter their metadata, breaking previous assumptions.</li></ul><p><strong>3. CloudFront Behavior</strong>:</p><ul><li>CloudFront caches responses aggressively. Even if a bucket policy or CORS configuration changes, cached responses might still lack the required headers.</li></ul><h4>Findings</h4><ol><li><strong>Objects Missing </strong><strong>ETag in Responses</strong>:</li></ol><ul><li>Some objects didn’t expose the ETag header, crucial for the browser&#39;s validation of CORS requests.</li></ul><p><strong>2. Partial CORS Coverage</strong>:</p><ul><li>The CORS policy allowed access but didn’t explicitly expose necessary headers (ETag, x-amz-request-id).</li></ul><p><strong>3. CloudFront Error Masking</strong>:</p><ul><li>CloudFront returned a generic 403 error when objects failed the CORS validation, making it harder to diagnose.</li></ul><h3>Testing Helpers</h3><p>1. AWS CLI:</p><ul><li><strong>Check Object Permissions</strong></li></ul><pre>aws s3api get-object-acl --bucket your-bucket-name --key &quot;path/to/image.jpg&quot;</pre><ul><li>Verify CORS Headers</li></ul><pre>curl -I https://your-bucket-name.s3.amazonaws.com/path/to/image.jpg</pre><h4>2. Browser Developer Tools:</h4><p>Open <strong>Network Tab</strong>.</p><ul><li>Look for failed requests and inspect response headers.</li><li>Confirm the presence of: Access-Control-Allow-Origin ,Access-Control-Expose-Headers.</li></ul><h4>3. CloudFront Logs:</h4><ul><li>Enable access logs to track request paths and errors:</li><li>Look for <strong>403 Forbidden</strong> responses.</li></ul><h3>Solution</h3><h4>Updated CORS Configuration:</h4><p>Adding the ETag header to the ExposeHeaders field resolved the issue.</p><p>Final CORS Policy:</p><pre>[<br>    {<br>        &quot;AllowedHeaders&quot;: [&quot;*&quot;],<br>        &quot;AllowedMethods&quot;: [&quot;GET&quot;, &quot;HEAD&quot;],<br>        &quot;AllowedOrigins&quot;: [&quot;*&quot;],<br>        &quot;ExposeHeaders&quot;: [&quot;ETag&quot;],<br>        &quot;MaxAgeSeconds&quot;: 3000<br>    }<br>]</pre><p><strong>Steps to Update</strong>:</p><ol><li>Log in to the AWS S3 console.</li><li>Navigate to the <strong>Permissions</strong> tab of your bucket.</li><li>Update the CORS configuration and save it.</li><li>Invalidate CloudFront cache:</li></ol><pre>aws cloudfront create-invalidation --distribution-id YOUR_DISTRIBUTION_ID --paths &quot;/*&quot;</pre><h3>Similar Situations</h3><ol><li><strong>Missing Custom Headers</strong>:</li></ol><ul><li>Requests for objects requiring custom metadata (e.g., Content-Disposition) fail unless explicitly exposed.</li></ul><p><strong>2. Old Bucket Policies</strong>:</p><ul><li>A bucket policy might unintentionally restrict access after policy changes or OAI (Origin Access Identity) enforcement.</li></ul><p>3. <strong>Cross-Origin POST Requests</strong>:</p><ul><li>Allowing POST or PUT methods without proper AllowedHeaders can lead to blocked requests.</li></ul><p><strong>4. CloudFront Behaviors</strong>:</p><ul><li>Cache misconfigurations or improper forwarding of headers like Origin</li></ul><h3>Conclusion</h3><p>CORS issues with Amazon S3 and CloudFront can be subtle and tricky. By systematically investigating the symptoms, testing configurations, and refining the CORS policy, these issues can be effectively resolved. Hopefully, this guide helps you troubleshoot and fix similar issues in your projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61f976bc41e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Essential Docker Commands: A Comprehensive Guide]]></title>
            <link>https://medium.com/@dpon1996/the-essential-docker-commands-a-comprehensive-guide-d5751b7c92f4?source=rss-bef3dc3f5af6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5751b7c92f4</guid>
            <category><![CDATA[docker-command]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[DHANESH PARAYANMARATH]]></dc:creator>
            <pubDate>Mon, 24 Jun 2024 17:29:59 GMT</pubDate>
            <atom:updated>2024-06-24T17:29:59.107Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QM5wgsMnhER1YrTE" /></figure><p>Docker is a powerful platform for developing, shipping, and running applications inside containers. Whether you’re a seasoned developer or a newcomer, knowing the most useful Docker commands can significantly improve your efficiency. In this guide, we’ll cover the essential Docker commands that every developer should know.</p><h3>1. Getting Started with Docker</h3><h4>docker — version</h4><p>This command checks the version of Docker installed on your system.</p><pre>docker --version</pre><h4>docker info</h4><p>Displays detailed information about the Docker installation, including the number of containers and images.</p><pre>docker info</pre><h3>2. Docker Images</h3><h4>docker pull</h4><p>Pulls an image from a Docker registry (such as Docker Hub).</p><pre>docker pull &lt;image_name&gt;</pre><h4>docker images</h4><p>Lists all Docker images available on your local system.</p><pre>docker images</pre><h4>docker rmi</h4><p>Removes one or more Docker images from your local system.</p><pre>docker rmi &lt;image_id&gt;</pre><h3>3. Docker Containers</h3><h4>docker run</h4><p>Runs a container from a Docker image. Common flags include -d for detached mode, -p to map ports, and --name to name the container.</p><pre>docker run -d -p 80:80 --name my_container &lt;image_name&gt;</pre><h4>docker ps</h4><p>Lists running containers. Adding -a will list all containers, including those that are stopped.</p><pre>docker ps<br>docker ps -a</pre><h4>docker stop</h4><p>Stops a running container.</p><pre>docker stop &lt;container_id&gt;</pre><h4>docker rm</h4><p>Removes a stopped container.</p><pre>docker rm &lt;container_id&gt;</pre><h4>docker exec</h4><p>Runs a command inside a running container. Useful for debugging and running ad-hoc tasks.</p><pre>docker exec -it &lt;container_id&gt; /bin/bash</pre><h3>4. Managing Docker Networks</h3><h4>docker network ls</h4><p>Lists all Docker networks on your system.</p><pre>docker network ls</pre><h4>docker network create</h4><p>Creates a new Docker network.</p><pre>docker network create &lt;network_name&gt;</pre><h4>docker network rm</h4><p>Removes one or more Docker networks.</p><pre>docker network rm &lt;network_name&gt;</pre><h3>5. Docker Volumes</h3><h4>docker volume ls</h4><p>Lists all Docker volumes.</p><pre>docker volume ls</pre><h4>docker volume create</h4><p>Creates a new Docker volume.</p><pre>docker volume create &lt;volume_name&gt;</pre><h4>docker volume rm</h4><p>Removes one or more Docker volumes.</p><pre>docker volume rm &lt;volume_name&gt;</pre><h3>6. Docker Compose</h3><h4>docker-compose up</h4><p>Starts and runs the entire application as defined in the docker-compose.yml file.</p><pre>docker-compose up</pre><h4>docker-compose down</h4><p>Stops and removes containers, networks, and volumes created by docker-compose up.</p><pre>docker-compose down</pre><h4>docker-compose logs</h4><p>Displays logs from the containers managed by Docker Compose.</p><pre>docker-compose logs</pre><h3>7. Cleaning Up</h3><h4>docker system prune</h4><p>Removes all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.</p><pre>docker system prune</pre><h4>docker volume prune</h4><p>Removes all unused volumes.</p><pre>docker volume prune</pre><h4>docker image prune</h4><p>Removes unused images. Use the -a flag to remove all unused images, not just dangling ones.</p><pre>docker image prune<br>docker image prune -a</pre><h3>Conclusion</h3><p>Docker is an incredibly powerful tool that can simplify the process of managing applications and their dependencies. By mastering the essential Docker commands covered in this guide, you can enhance your efficiency, streamline your workflows, and ensure consistent environments from development to production.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5751b7c92f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Install and Use Docker on Ubuntu 22.04]]></title>
            <link>https://medium.com/@dpon1996/how-to-install-and-use-docker-on-ubuntu-22-04-6ea74ea91d05?source=rss-bef3dc3f5af6------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ea74ea91d05</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[install-docker-in-ubuntu]]></category>
            <category><![CDATA[docker-installation]]></category>
            <dc:creator><![CDATA[DHANESH PARAYANMARATH]]></dc:creator>
            <pubDate>Sat, 22 Jun 2024 18:14:20 GMT</pubDate>
            <atom:updated>2024-06-22T18:14:20.194Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Nc8icYqr_vQz7rOP" /></figure><p>Docker is a platform that simplifies the creation, deployment, and running of applications by using containers. Containers allow developers to package up an application with all the parts it needs, such as libraries and other dependencies, and ship it all out as one package. Here’s a step-by-step guide on how to install and use Docker on Ubuntu 22.04.</p><h4>Step 1: Update Your System</h4><p>Before installing Docker, it’s always good practice to update the package index and upgrade your system packages to the latest versions.</p><pre>sudo apt update<br>sudo apt upgrade -y</pre><h4>Step 2: Install Required Packages</h4><p>Install the required packages to allow apt to use packages over HTTPS.</p><pre>sudo apt install apt-transport-https ca-certificates curl software-properties-common -y</pre><h4>Step 3: Add Docker’s Official GPG Key</h4><p>Add Docker’s official GPG key to ensure the authenticity of the packages.</p><pre>curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg</pre><h4>Step 4: Set Up the Docker Repository</h4><p>Add the Docker APT repository to your system’s software repository list.</p><pre>echo &quot;deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable&quot; | sudo tee /etc/apt/sources.list.d/docker.list &gt; /dev/null</pre><h4>Step 5: Update Package Index Again</h4><p>Update the package index again to include the Docker repository.</p><pre>sudo apt update</pre><h4>Step 6: Install Docker</h4><p>Now, install Docker from the Docker repository.</p><pre>sudo apt install docker-ce -y</pre><h4>Step 7: Verify Docker Installation</h4><p>Verify that Docker is installed correctly by running the hello-world image.</p><pre>sudo docker run hello-world</pre><p>If Docker is installed and working correctly, you should see a message saying “Hello from Docker!”.</p><h4>Step 8: Manage Docker as a Non-Root User</h4><p>To avoid typing sudo whenever you run the docker command, add your user to the docker group.</p><ol><li>Add the docker group if it doesn’t already exist.</li></ol><pre>sudo groupadd docker</pre><p>2. Add your user to the docker group.</p><pre>sudo usermod -aG docker $USER</pre><p>3. Confirm that your user is now added to the <strong>docker</strong> group by typing:</p><pre>groups</pre><p>4. Verify that you can run docker commands without sudo.</p><pre>docker run hello-world</pre><h4>Step 9: Enable Docker to Start on Boot</h4><p>Ensure that Docker starts automatically at boot time.</p><pre>sudo systemctl enable docker</pre><h4>Basic Docker Usage</h4><ol><li>Pull an Image<br>Download an image from Docker Hub. For example, to pull the latest Ubuntu image:</li></ol><pre>docker pull ubuntu</pre><p>2. Run a Container<br>Run a container from the pulled image:</p><pre>docker run -it ubuntu</pre><p>This command runs an Ubuntu container interactively with a terminal.</p><p>3. List Docker Containers<br>To list all running containers:</p><pre>docker ps</pre><p>To list all containers, including those that are stopped:</p><pre>docker ps -a</pre><p>4. Stop a Container<br>To stop a running container, use its container ID or name:</p><pre>docker stop &lt;container_id_or_name&gt;</pre><p>5. Remove a Container<br>To remove a stopped container:</p><pre>docker rm &lt;container_id_or_name&gt;</pre><p>6. Remove an Image<br>To remove an image by its ID or name:</p><pre>docker rmi &lt;image_id_or_name&gt;</pre><h3>Conclusion</h3><p>Congratulations! You’ve successfully installed Docker on your Ubuntu 22.04 system and explored the basics of its usage. By leveraging Docker, you can significantly enhance your development and deployment processes, ensuring consistent environments across various stages of your workflow. Docker’s containerization technology not only simplifies dependency management but also accelerates the transition from development to production, making your applications more scalable and reliable.</p><p>Whether you’re a developer looking to streamline your coding environment, a system administrator aiming to optimize deployment strategies, or a DevOps engineer seeking better CI/CD pipelines, Docker offers powerful tools to meet your needs. Dive deeper into Docker’s vast ecosystem to unlock even more potential and transform the way you manage and deploy your applications. Happy containerizing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ea74ea91d05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Dynamically Measure Widget Size in Flutter]]></title>
            <link>https://medium.com/@dpon1996/how-to-dynamically-measure-widget-size-in-flutter-e4004f3bd5fb?source=rss-bef3dc3f5af6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4004f3bd5fb</guid>
            <category><![CDATA[widget-size]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-dynamic-size]]></category>
            <category><![CDATA[sample-size-calculation]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[DHANESH PARAYANMARATH]]></dc:creator>
            <pubDate>Fri, 21 Jun 2024 07:15:35 GMT</pubDate>
            <atom:updated>2024-06-21T07:15:35.361Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8SfMmt0IoXWs_jQw" /></figure><p>One of the common challenges in Flutter development is determining the dynamic size of a widget after it has been rendered. This can be crucial for various layout adjustments and animations. In this post, I’ll show you a simple yet effective way to measure the size of a widget using a custom widget.</p><h3>The SizeMeasureWidget</h3><p>The core of our solution is a custom SizeMeasureWidget that wraps any widget and provides its size once it&#39;s rendered.</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class SizeMeasureWidget extends StatefulWidget {<br>  final Widget child;<br>  final ValueChanged&lt;Size&gt; onSizeMeasured;<br><br>  const SizeMeasureWidget({<br>    Key? key,<br>    required this.onSizeMeasured,<br>    required this.child,<br>  }) : super(key: key);<br><br>  @override<br>  _SizeMeasureWidgetState createState() =&gt; _SizeMeasureWidgetState();<br>}<br><br>class _SizeMeasureWidgetState extends State&lt;SizeMeasureWidget&gt; {<br>  final GlobalKey _sizeKey = GlobalKey();<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Container(<br>      key: _sizeKey,<br>      child: widget.child,<br>    );<br>  }<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    WidgetsBinding.instance.addPostFrameCallback((_) {<br>      _getSize();<br>    });<br>  }<br><br>  void _getSize() {<br>    RenderBox renderBox = _sizeKey.currentContext!.findRenderObject() as RenderBox;<br>    Size size = renderBox.size;<br>    widget.onSizeMeasured(size);<br>  }<br>}</pre><h4>How It Works</h4><ol><li><strong>Stateful Widget</strong>: SizeMeasureWidget is a stateful widget that takes a child widget and a callback function onSizeMeasured.</li><li><strong>GlobalKey</strong>: We use a GlobalKey to uniquely identify the widget and get its context.</li><li><strong>Post Frame Callback</strong>: In initState, we register a callback with WidgetsBinding.instance.addPostFrameCallback to execute code after the widget tree has been laid out.</li><li><strong>RenderBox</strong>: Using the GlobalKey, we get the RenderBox of the widget and then fetch its size.</li><li><strong>Callback</strong>: Finally, we call the onSizeMeasured callback with the size of the widget.</li></ol><h3>Using SizeMeasureWidget</h3><p>Here’s how you can use SizeMeasureWidget in your application:</p><pre>void main() {<br>  runApp(MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      home: Scaffold(<br>        appBar: AppBar(title: Text(&#39;Dynamic Size Measurement&#39;)),<br>        body: Center(<br>          child: SizeMeasureWidget(<br>            onSizeMeasured: (size) {<br>              print(&quot;Widget size: $size&quot;);<br>            },<br>            child: Container(<br>              color: Colors.blue,<br>              height: 200,<br>              width: 200,<br>              child: Center(child: Text(&#39;Measure my size!&#39;)),<br>            ),<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><h3>Explanation</h3><p>In this example:</p><ul><li>We wrap a Container inside SizeMeasureWidget.</li><li>The onSizeMeasured callback prints the size of the Container to the console.</li></ul><h3>Benefits</h3><ul><li><strong>Dynamic Layout Adjustments</strong>: You can adjust layouts dynamically based on the size of widgets.</li><li><strong>Animations</strong>: Create more complex animations where the size of elements is known.</li><li><strong>Responsive Design</strong>: Build more responsive and adaptive UIs.</li></ul><h3>Conclusion</h3><p>By using SizeMeasureWidget, you can easily measure and react to the dynamic size of any widget in Flutter. This technique is invaluable for creating flexible, responsive layouts. Give it a try in your projects and see how it simplifies your layout logic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4004f3bd5fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Nginx: Essential Commands for Efficient Server Management]]></title>
            <link>https://medium.com/@dpon1996/mastering-nginx-essential-commands-for-efficient-server-management-29e90329285c?source=rss-bef3dc3f5af6------2</link>
            <guid isPermaLink="false">https://medium.com/p/29e90329285c</guid>
            <category><![CDATA[ubuntu-server-management]]></category>
            <category><![CDATA[nginx-configuration]]></category>
            <category><![CDATA[nginx-commands]]></category>
            <category><![CDATA[web-server-tutorial]]></category>
            <category><![CDATA[nginx-troubleshooting]]></category>
            <dc:creator><![CDATA[DHANESH PARAYANMARATH]]></dc:creator>
            <pubDate>Thu, 20 Jun 2024 17:18:36 GMT</pubDate>
            <atom:updated>2024-06-20T17:18:36.559Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KHQEQyHEt2Fd3n56.png" /></figure><p>Nginx is a powerful and widely-used web server that excels in serving static content, acting as a reverse proxy, load balancing, and more. For administrators, mastering the essential Nginx commands is crucial for efficient server management. In this blog post, we’ll explore the most useful Nginx commands that will help you start, stop, reload configurations, check status, and manage logs effectively.</p><h3>Basic Nginx Commands</h3><h4>1. Start Nginx</h4><p>Starting the Nginx service is straightforward. Use the following command</p><pre>sudo systemctl start nginx</pre><p>This command initializes the Nginx service, making it ready to handle requests.</p><h4>2. Stop Nginx</h4><p>To stop the Nginx service, use</p><pre>sudo systemctl stop nginx</pre><p>This command will halt the Nginx service, stopping it from handling any further requests.</p><h4>3. Restart Nginx</h4><p>Restarting Nginx is useful when you make significant changes to the configuration. It stops and then starts the Nginx service</p><pre>sudo systemctl restart nginx</pre><h4>4. Reload Nginx</h4><p>Reloading Nginx is a safer way to apply configuration changes without dropping existing connections</p><pre>sudo systemctl reload nginx</pre><h4>5. Check Nginx Status</h4><p>To check the current status of the Nginx service, use</p><pre>sudo systemctl status nginx</pre><p>This command provides information on whether Nginx is running and its current state.</p><h3>Configuration Management</h3><h4>1. Test Nginx Configuration</h4><p>Before reloading or restarting Nginx, it’s crucial to ensure that your configuration files are error-free. Test the configuration with</p><pre>sudo nginx -t</pre><p>This command checks the syntax of the Nginx configuration files.</p><h4>2. Test Nginx Configuration with Debug Output</h4><p>For a more detailed check, including the current configuration settings, use</p><pre>sudo nginx -T</pre><p>This command tests the configuration and prints the output to the terminal, which is useful for debugging complex setups.</p><h3>Log Management</h3><h4>1. View Nginx Access Logs</h4><p>To monitor incoming requests in real-time, view the Nginx access logs</p><pre>sudo tail -f /var/log/nginx/access.log</pre><p>This command continuously displays the latest entries in the access log.</p><h4>2. View Nginx Error Logs</h4><p>To monitor errors and issues in real-time, view the Nginx error logs</p><pre>sudo tail -f /var/log/nginx/error.log</pre><p>This command continuously displays the latest entries in the error log.</p><h3>Managing Nginx Processes</h3><h4>1. List Active Nginx Processes</h4><p>To list all active Nginx processes, use</p><pre>ps aux | grep nginx</pre><p>This command is useful for troubleshooting and ensuring that Nginx is running correctly.</p><h4>2. Reload Nginx without Dropping Connections</h4><p>For a graceful reload of Nginx configurations, use</p><pre>sudo nginx -s reload</pre><p>This sends a signal to Nginx to reload its configuration without dropping connections, similar to systemctl reload nginx.</p><h3>Enabling and Disabling Sites</h3><h4>1. Enable a Site</h4><p>To enable a site configuration, create a symbolic link from the configuration file in sites-available to sites-enabled</p><pre>sudo ln -s /etc/nginx/sites-available/your_site /etc/nginx/sites-enabled/</pre><h4>2. Disable a Site</h4><p>To disable a site configuration, remove the symbolic link from sites-enabled</p><pre>sudo rm /etc/nginx/sites-enabled/your_site</pre><h3>Miscellaneous Commands</h3><h4>1. Display Nginx Version</h4><p>To display the installed version of Nginx, use</p><pre>nginx -v</pre><h4>2. Display Nginx Version and Configuration Options</h4><p>For detailed information on the installed version and configuration options Nginx was compiled with, use</p><pre>nginx -V</pre><h4>3. Check Nginx Configuration Directives</h4><p>To search for specific configuration directives in the Nginx configuration, use</p><pre>sudo nginx -T | grep directive_name</pre><p>Replace directive_name with the actual directive you want to search for.</p><h3>Conclusion</h3><p>Mastering these Nginx commands will enhance your ability to manage your web server effectively, troubleshoot issues, and ensure smooth operation. From starting and stopping the service to managing logs and configurations, these commands are essential tools for any Nginx administrator.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29e90329285c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Install Nginx on Ubuntu: A Step-by-Step Guide]]></title>
            <link>https://medium.com/@dpon1996/how-to-install-nginx-on-ubuntu-a-step-by-step-guide-424eeb38ad5f?source=rss-bef3dc3f5af6------2</link>
            <guid isPermaLink="false">https://medium.com/p/424eeb38ad5f</guid>
            <category><![CDATA[install-nginx]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[nginx-configuration]]></category>
            <dc:creator><![CDATA[DHANESH PARAYANMARATH]]></dc:creator>
            <pubDate>Wed, 19 Jun 2024 19:00:30 GMT</pubDate>
            <atom:updated>2024-06-19T19:03:20.271Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EiRg13xfwW1xQXXPS-wRUA.jpeg" /></figure><p>Welcome to this comprehensive guide on how to install Nginx on Ubuntu! Whether you’re setting up a web server for the first time or looking to switch from another web server software, this guide will walk you through the entire installation process. Let’s dive in.</p><h4>What is Nginx?</h4><p>Nginx is a high-performance web server and reverse proxy server. It’s known for its stability, rich feature set, simple configuration, and low resource consumption. Nginx is widely used for serving static files, load balancing, and handling high-traffic websites.</p><h4>Prerequisites</h4><p>Before we begin, ensure you have the following:</p><ul><li>An Ubuntu system (this guide assumes Ubuntu 20.04 LTS, but it should work for other versions as well).</li><li>A user with sudo privileges.</li></ul><h4>Step 1: Update Your System</h4><p>First, it’s good practice to update your package list and upgrade the existing packages. Open your terminal and run:</p><pre>sudo apt update<br>sudo apt upgrade</pre><p>This ensures you have the latest security updates and bug fixes.</p><h4>Step 2: Install Nginx</h4><p>Nginx is available in the default Ubuntu repositories, making installation straightforward. To install Nginx, use the following command:</p><pre>sudo apt install nginx</pre><p>You’ll be prompted to confirm the installation. Type Y and press Enter.</p><h4>Step 3: Start and Enable Nginx</h4><p>Once Nginx is installed, start the Nginx service and enable it to start on boot:</p><pre>sudo systemctl start nginx<br>sudo systemctl enable nginx</pre><p>To verify that Nginx is running, use the command:</p><pre>sudo systemctl status nginx</pre><pre>Output<br>● nginx.service - A high performance web server and a reverse proxy server<br>   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)<br>   Active: active (running) since Fri 2020-04-20 16:08:19 UTC; 3 days ago<br>     Docs: man:nginx(8)<br> Main PID: 2369 (nginx)<br>    Tasks: 2 (limit: 1153)<br>   Memory: 3.5M<br>   CGroup: /system.slice/nginx.service<br>           ├─2369 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;<br>           └─2380 nginx: worker process</pre><h4>Step 4: Adjust Firewall Settings</h4><p>If you have a firewall enabled, you need to allow traffic on HTTP (port 80) and HTTPS (port 443). Use the following commands to adjust your firewall settings:</p><pre>sudo ufw allow &#39;Nginx HTTP&#39;</pre><p>Then, verify the changes:</p><pre>sudo ufw status</pre><p>The output will indicated which HTTP traffic is allowed:</p><pre>Output<br>Status: active<br><br>To                         Action      From<br>--                         ------      ----<br>OpenSSH                    ALLOW       Anywhere                  <br>Nginx HTTP                 ALLOW       Anywhere                  <br>OpenSSH (v6)               ALLOW       Anywhere (v6)             <br>Nginx HTTP (v6)            ALLOW       Anywhere (v6)</pre><h4>Step 5: Verify Nginx Installation</h4><p>To confirm that Nginx is installed correctly and serving web pages, open a web browser and enter your server’s IP address. You should see the default Nginx welcome page, which means Nginx is working correctly.</p><pre>http://your_server_ip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/0*f9P-Cfg-YorxXSBh.png" /></figure><h4>Step 6: Setting Up Server Blocks</h4><p>When using the Nginx web server, server blocks (similar to virtual hosts in Apache) are essential for hosting multiple domains on a single server. In this section, we’ll set up a domain called your_domain. Be sure to replace your_domain with your actual domain name throughout this tutorial.</p><p>Nginx on Ubuntu 20.04 comes with one server block enabled by default. This default server block is configured to serve documents from /var/www/html. While this setup works well for a single site, it becomes cumbersome when hosting multiple sites. To manage multiple sites efficiently, we&#39;ll create a directory structure within /var/www for your_domain and leave /var/www/html as the default directory for unmatched client requests.</p><h4>1. Create the Directory Structure</h4><p>First, create the directory for your_domain using the -p flag to ensure any necessary parent directories are created:</p><pre>sudo mkdir -p /var/www/your_domain/html</pre><h4>2. Assign Ownership</h4><p>Next, assign ownership of the directory to your current user using the $USER environment variable. This ensures that you have the necessary permissions to manage files in this directory:</p><pre>sudo chown -R $USER:$USER /var/www/your_domain/html</pre><h4>3. Set Correct Permissions</h4><p>To ensure that the permissions are correct, allowing the owner to read, write, and execute the files while granting only read and execute permissions to groups and others, run the following command:</p><pre>sudo chmod -R 755 /var/www/your_domain</pre><h4>4. Create a Sample HTML Page</h4><p>Create a sample index.html page to serve as the home page for your_domain. Use nano or your favorite text editor:</p><pre>sudo nano /var/www/your_domain/html/index.html</pre><p>Inside the file, add the following sample HTML content:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>    &lt;head&gt;<br>        &lt;title&gt;Welcome to your_domain!&lt;/title&gt;<br>    &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;h1&gt;Success! The your_domain server block is working!&lt;/h1&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Save and close the file by pressing Ctrl+X, then Y, and Enter.</p><h4>5. Create a Server Block Configuration</h4><p>To configure Nginx to serve the content from the new directory, create a new server block configuration file in the /etc/nginx/sites-available/ directory:</p><pre>sudo nano /etc/nginx/sites-available/your_domain</pre><p>Paste the following configuration block into the file:</p><pre>server {<br>    listen 80;<br>    listen [::]:80;<br><br>    root /var/www/your_domain/html;<br>    index index.html index.htm index.nginx-debian.html;<br><br>    server_name your_domain www.your_domain;<br><br>    location / {<br>        try_files $uri $uri/ =404;<br>    }<br>}</pre><p>This configuration:</p><ul><li>Sets the root directory to /var/www/your_domain/html.</li><li>Defines the server_name to match your_domain and <a href="http://www.your_domain./">www.your_domain.</a></li><li>Configures Nginx to serve the index.html file.</li></ul><p>Save and close the file by pressing Ctrl+X, then Y, and Enter.</p><h4>6. Enable the Server Block</h4><p>To enable the new server block, create a symbolic link from the configuration file in sites-available to the sites-enabled directory. Nginx reads the configuration files in sites-enabled during startup:</p><pre>sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/</pre><p>Nginx uses symbolic links (symlinks) to manage enabled server blocks. Creating a symlink is similar to creating a shortcut, allowing you to enable or disable server blocks by adding or removing these symlinks.</p><h4>7. Test Nginx Configuration</h4><p>Before reloading Nginx, test the configuration for syntax errors:</p><pre>sudo nginx -t</pre><p>If the test is successful, reload Nginx to apply the changes:</p><pre>sudo systemctl reload nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/0*C6kG93lpM89UZUHN.PNG" /></figure><h3>Conclusion</h3><p>Congratulations! You’ve successfully installed Nginx on your Ubuntu server. From here, you can explore more advanced configurations, set up SSL/TLS for secure connections, and optimize Nginx for your specific use case.</p><p>Nginx is a powerful tool that can significantly enhance your web server’s performance and reliability. Happy hosting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=424eeb38ad5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>