본문 바로가기
서버 및 보안

How To Install WordPress with Nginx

by 다움위키 2023. 12. 20.

웹으로 컨텐츠를 관리하는 것 중에서 WordPress가 많이 거른됩니다. 여기서는 단순히 설치해서 다른 것들과 차이점을 간략히 살펴보고자 합니다.

데이터베이스 생성

  • sudo mysql -u root -p
MariaDB [(none)]> CREATE DATABASE wordpress;
MariaDB [(none)]> CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

wordpress 설치

설정

  • cd /var/www/html/wordpress
  • sudo cp wp-config-sample.php wp-config.php
  • nano /var/www/html/wordpress/wp-config.php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
...
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');
  • cd /var/www/html
  • sudo chown www-data:www-data wordpress
  • cd wordpress
  • sudo mkdir wp-content/uploads
  • sudo chown -R www-data:www-data wp-content/uploads

Nginx 설정

  • nano /etc/nginx/site-available/default
	location /wordpress {
	#	auth_basic		"Restricted";
	#	auth_basic_user_file	/etc/nginx/mypasswd;
		root /var/www/html;
		index index.html index.htm index.php;
		
		location ~ ^/wordpress/(config\.php|common\.php|includes|cache|files|store|images/avatars/upload) {
            		deny all;
            		internal;
        	}


		location ~ ^/wordpress/(.+\.php)$ {
			#try_files $uri =404;
			try_files $uri @wordpresshandler;
			root /var/www/html;
			fastcgi_pass unix:/var/run/php5-fpm.sock;
			fastcgi_index index.php;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			include /etc/nginx/fastcgi_params;
		}

		location ~* ^/wordpress/(.+\.(gif|jp?eg|png|css|js|cgi|pl|ico|swf|flv|s?html|php|xap|py|xml|txt))$ {
			#access_log        off;
			#log_not_found     off;
			#expires           360d;
			expires 1y;
			root /var/www/html;
		}

		#CatchAll - last generates 301 moved permanently
		location ~ ^/wordpress/.+$ {
			#try_files $uri @wordpresshandler;
			rewrite ^ /wordpress last;
		}
	}
	
	location @wordpresshandler {
		rewrite ^ /wordpress last;
	}
  • sudo systemctl restart nginx

http://localhost/wordpress

  • Site title
  • Username
  • Password
  • Your Email
  • Search Engine Visibility

External Resources