{"id":478,"date":"2025-01-10T23:56:26","date_gmt":"2025-01-10T19:56:26","guid":{"rendered":"https:\/\/hostatto.com\/blog\/?p=478"},"modified":"2025-01-15T12:17:47","modified_gmt":"2025-01-15T08:17:47","slug":"set-up-a-nginx-server-for-debian-12","status":"publish","type":"post","link":"https:\/\/hostatto.com\/blog\/set-up-a-nginx-server-for-debian-12.html","title":{"rendered":"Set up a NGINX server for Debian 12"},"content":{"rendered":"<p>After <a href=\"https:\/\/hostatto.com\/blog\/blog\/linux\/install-nginx-on-debian-12.html\">installing the NGINX<\/a> server, NGINX is directed to the folder<\/p>\n<blockquote><p>\/usr\/share\/nginx\/html<\/p><\/blockquote>\n<p>Let's change this path.<br \/>\nI want my site example.com to be in a folder <strong>var\/www\/<\/strong><br \/>\n\u0421reate a <strong>example.com<\/strong> folder<\/p>\n<blockquote><p>mkdir \/var\/www\/example.com<\/p><\/blockquote>\n<p>Set folder permissions 755<\/p>\n<blockquote><p>chmod 755 \/var\/www\/example.com<\/p><\/blockquote>\n<p><strong>755<\/strong> ( drwxr-xr-x ) everyone can read this directory, but only the owner can change its contents<\/p>\n<p>Create a new file index.php in the folder example.com<\/p>\n<blockquote><p>touch \/var\/www\/example.com\/index.php<\/p><\/blockquote>\n<p>Set file index.php permissions 644<\/p>\n<blockquote><p>chmod 644 \/var\/www\/example.com\/index.php<\/p><\/blockquote>\n<p><strong>644<\/strong> (-rw-r--r--) only the owner has read and write permission; group and others have read-only access<\/p>\n<p>Set the owner www-data and group www-data for the example.com folder and also for all folders and files inside the example.com folder<\/p>\n<blockquote><p>chown -R www-data:www-data \/var\/www\/example.com<\/p><\/blockquote>\n<p><strong>Notice:<\/strong> User and group settings are in the file<\/p>\n<blockquote><p>\/etc\/php\/8.3\/fpm\/pool.d\/www.conf<\/p><\/blockquote>\n<p>Open the file index.php and write in it<\/p>\n<blockquote><p>&lt;?php<br \/>\necho \"Hello world!\";<br \/>\n?&gt;<\/p><\/blockquote>\n<p>Now open the file <strong>default.conf<\/strong><\/p>\n<blockquote><p>nano \/etc\/nginx\/conf.d\/default.conf<\/p><\/blockquote>\n<p>And write to it<\/p>\n<pre class=\"lang:default decode:true\">server {\r\n    listen      80 default_server;\r\n    server_name localhost;\r\n\r\n    root \/var\/www\/;\r\n\r\n    location \/ {\r\n        try_files $uri $uri\/ \/index.php?$args;\r\n    }\r\n\r\n    location \/example.com\/ {\r\n        try_files $uri \/example.com\/index.php?$args;\r\n    }\r\n\r\n    location ~ \\.php$ {\r\n        fastcgi_index index.php;\r\n        fastcgi_pass unix:\/run\/php\/php8.3-fpm.sock;\r\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n        fastcgi_split_path_info ^(.+?\\.php)(\/.*)$;\r\n        try_files $uri =404;\r\n        include fastcgi_params;\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>Now open the file <strong>nginx.conf<\/strong><\/p>\n<blockquote><p>nano \/etc\/nginx\/nginx.conf<\/p><\/blockquote>\n<p>And in the first line replace<\/p>\n<blockquote><p>user nginx;<\/p><\/blockquote>\n<p>replace with<\/p>\n<blockquote><p>user www-data;<\/p><\/blockquote>\n<p>Restart the server<\/p>\n<blockquote><p>service nginx restart<\/p><\/blockquote>\n<p>Opening the site in a browser<\/p>\n<blockquote><p>http:\/\/localhost\/example.com\/<\/p><\/blockquote>\n<p>If you saw the text<\/p>\n<blockquote><p>Hello world<\/p><\/blockquote>\n<p>NGINX server setup done correctly<\/p>\n<p>If an error occurs, you can find the cause of the error in the file error.log<\/p>\n<blockquote><p>\/var\/log\/nginx\/error.log<\/p><\/blockquote>\n<p>My simple config file <strong>nginx.conf<\/strong> looks like this<\/p>\n<pre class=\"lang:default decode:true \">user www-data;\r\nworker_processes auto;\r\n\r\npid \/var\/run\/nginx.pid;\r\n\r\nevents {\r\n    worker_connections 1024;\r\n}\r\n\r\nhttp {\r\n\r\n    include \/etc\/nginx\/mime.types;\r\n    default_type application\/octet-stream;\r\n\r\n    log_format main '$remote_addr - $remote_user [$time_local] \"$request\" '\r\n    '$status $body_bytes_sent \"$http_referer\" '\r\n    '\"$http_user_agent\" \"$http_x_forwarded_for\"';\r\n\r\n    access_log \/var\/log\/nginx\/access.log main;\r\n    error_log \/var\/log\/nginx\/error.log notice;\r\n\r\n    sendfile on;\r\n    keepalive_timeout 65;\r\n\r\n    include \/etc\/nginx\/conf.d\/*.conf;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>...<\/p>\n","protected":false},"author":1,"featured_media":505,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/posts\/478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/comments?post=478"}],"version-history":[{"count":0,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/posts\/478\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/media\/505"}],"wp:attachment":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/media?parent=478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/categories?post=478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/tags?post=478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}