Wordpress publishing fail after change permalink option

nginx php mysql 조합으로 워드프레스 홈페이지를 제작중이다.
워드프레스에서의 각 페이지와 포스트의 기본 URL 링크는 ?p=1 와 같은식의 id번호값이 들어간다.
하지만 앞으로 여러가지 상황과 구글 SEO 최적화를 위해 퍼머링크를 포스트 제목등으로 바꿀 필요가 있다.

아파치는 안해봐서 모르겠지만.

결론부터 얘기하자면
nginx에서 /etc/nginx/sites-available/default 이 파일 설정을 잘 해주어야 된다.

일단 본문 그대로 가져온다면

################## HTTP  웹페이지 도메인
server { 
    listen 80 default_server; 
    listen [::]:80 default_server; 
    root /var/www/html; 
    index index.php index.html index.htm index.nginx-debian.html; 
    server_name 웹페이지 도메인;

    location / { 
        try_files $uri $uri/ =404; 
        # 워드프레스 고유주소(permalink)를 기본(plain)에서 글이름(post name)등 다른걸로 바꾸었을 때 기존 글들이 404페이지가 되는 것 우회
       if (!-e $request_filename) { 
         rewrite ^.*$ /index.php last; 
       }
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params; 
        fastcgi_read_timeout 300;
    }

    location ~ /\.ht {
        deny all;
   }
}


이런식으로 작성이 되어야 한다.

그동안 나는 이 파일은 그저 php와 nginx를 연동하는데만 목적이 있는줄 알았다. 사실 맞다.
nginx와 최대한 간단하게 작성하고자

fastcgi-pass unix:/run/php/php7.2-fpm.sock;

이 문장만 넣었었는데 다른것도 다 넣으니 이제 되더라.

원리는 잘 모르겠고 퍼머링크 에러나면 이것부터 해보시오.

No comments:

Post a Comment